我无法弄清楚如何过滤组合框以仅显示包含迄今为止输入的文本的项目。
这是构建组合框绑定到的数据表的函数:
Function users() As DataTable
Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim idCoulumn As DataColumn
Dim nameCoulumn As DataColumn
dt = New DataTable()
idCoulumn = New DataColumn("ID", Type.GetType("System.Int32"))
nameCoulumn = New DataColumn("Name", Type.GetType("System.String"))
dt.Columns.Add(idCoulumn)
dt.Columns.Add(nameCoulumn)
dr = dt.NewRow()
dr("ID") = 1
dr("Name") = "Zuse, Konrad"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr("ID") = 2
dr("Name") = "Torvalds, Linus"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr("ID") = 3
dr("Name") = "Babbage, Charles"
dt.Rows.Add(dr)
ds.Tables.Add(dt)
Return dt
End Function
如果我键入“u”,我将如何对其进行编程以仅显示 Linus 和 Zuse 条目?
我已经尝试过这样的事情,但我真的不明白该怎么做:
Private Sub userKeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles cb_user.KeyUp
cb_user.IsDropDownOpen = True
cb_user.Items.Filter = Function(item)
Return item.ToString().Contains(cb_user.Text.Trim())
End Function
End Sub