在下面的表单中,网格包含一个下拉菜单控件,该控件包含应该进入网格的产品,下拉菜单填充表单加载事件, a - z产品出现在下拉菜单中。
见下图:
点击这里查看我的表单和下拉http://imageshack.com/a/img838/5697/1knn.jpg
如您所见,当我按下"G"时,它将显示以G开头的产品名称和其他产品名称。我想要的是:如果我按下'G',它应该只显示以G开头的产品名称。
Dim adapter As New NpgsqlDataAdapter(strSql, GenConnection)
adapter.Fill(SourceDataSetProducts)
bindSourceSale.DataSource = SourceDataSetProducts
SourceDataSetProducts.PrimaryKey = New DataColumn() {SourceDataSetProducts.Columns("ProductId")}
drpDwnProducts.DataSource = Nothing
drpDwnProducts.DataSource = bindSourceSale
drpDwnProducts.DisplayMember = "ProductName"
drpDwnProducts.ColumnHeaders = True
drpDwnProducts.Width = 800
用这种方法,我在form load中填充了下拉菜单
' Get a DataView of the table contained in the dataset.
Dim tables As DataTableCollection = set1.Tables
Dim view1 As New DataView(tables(0))
' Create a BindingSource and set its DataSource property to
' the DataView.
Dim source1 As New BindingSource()
source1.DataSource = view1
' Set the data source for the products...
Dropdown.DataSource = source1
' The Filter string can include Boolean expressions.
source1.Filter = "products = 'whatever'"
你可以用like as well…
Source.Filter = "products like' %whatever%'"