根据文本框输入在组合框中选择值

时间:2019-01-14 11:29:21

标签: vb.net

我有这个组合框:

Public Function setCities(ByVal Optional tag As Integer = 0)
    ptbrgrad.Items.Clear()
    Dim barmanager As New BarManager
    Dim ComboBoxItem1 = New ComboBoxItem()
    ComboBoxItem1.Content = "New"
    ComboBoxItem1.Name = "New"
    ComboBoxItem1.Tag = "0"
    ptbrgrad.Items.Add(ComboBoxItem1)
    ComboBoxItem1.IsSelected = True
    dataView.Sort = " postNumber ASC"
    dataTable = dataView.ToTable()
    For Each row As DataRow In dataTable.Rows
        Dim ComboBoxItem = New ComboBoxItem()
        ComboBoxItem.Content = row("cityName")
        ComboBoxItem.Name = "Nom"
        ComboBoxItem.Tag = row("idCity")
        ComboBoxItem.ToolTip = row("postNumber")
        ptbrgrad.Items.Add(ComboBoxItem)
    Next row
    If tag = 0 Then
        ptbrgrad.SelectedIndex = 0
    Else
        ptbrgrad.SelectedValue = tag
    End If
    Return True
End Function  

我在表单上有一个文本框。 当用户在文本框中输入值时,组合框应将selectedValue更改为以textbox.text开头的项目。

这就是dataView的工作方式:

dataView.RowFilter = String.Format("postNumberLIKE '{0}%'", textbox1.Text)

但是我希望每次输入文本时跳过网格中的加载项。

1 个答案:

答案 0 :(得分:0)

要执行类似的操作,请从组合框项目中创建一个数组,如下所示:

list.stream() // 1,2,0,5,0
    .filter(x -> x > 0) // 1,2,5
    .map(x -> x - 1) // 0,1,4
    .collect(Collectors.toList()); // will return list with three elements [0,1,4]

然后在TextBox的Dim items() As String Dim id As Integer = 0 For Each s As String In ComboBox.Items items(id) = s id += 1 Next 事件下,输入

TextChanged