下拉控制搜索方法

时间:2014-03-20 07:06:22

标签: c# vb.net

在以下表单中,网格包含 dropDown 控件,其中包含应在网格上输入的产品, dropDown 填写表单加载事件,AZ产品出现在 dropDown 中。

见下图:

click here to see my form and dropdown 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

通过这种方式,我曾经在表单加载中填充dropDown。

1 个答案:

答案 0 :(得分:0)

  ' 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'"

您也可以使用...

 Source.Filter = "products like' %whatever%'"

这是您需要的良好开端。

相关问题