根据用户输入搜索组合框下拉列表

时间:2015-05-14 11:16:03

标签: vb.net string search filter combobox

我有一个包含列表项的组合框:

ABC BAC DEE

如何根据输入建议列表。例如,如果用户键入A,则应显示: ABC BAC 因为它们都包含字符串字符A。

1 个答案:

答案 0 :(得分:0)

    Dim AList As List(Of String) = New List(Of String)
    ' Iterate through all the items in the combobox.
    For Each item As Object In ComboBox1.Items
        ' If the current item contains A then add to the list.
        If item.ToString.Contains("A") Then
            AList.Add(item.ToString)
        End If
    Next

或者你可以通过LINQ来实现,这基本上是相同的:

    Dim AList As List(Of String) = New List(Of String)
    Dim query = From item In ComboBox1.Items
                Where item.ToString.Contains("A")
                Select item

    For Each item in query
        AList.Add(item.ToString)
    Next