使用 2 个文本框过滤绑定源
Filtering Bindingsource using 2 textbox
我正在使用 Visual Studio 10,使用 Oracle 数据库在 VB 中编程。
我需要使用 2 个变量对 DataGridView 进行筛选。到目前为止的代码如下所示:
TableBindingSource1.Filter = "[FIELD1] = '" & TextBox1.Text & "'"
DataGridView1.Refresh()
如何在此示例中插入 FIELD2 和 Textbox2,使两个过滤器一起工作?非常感谢。
可能是这样的:
Me.BindingSource.Filter = "FIELD1= '" & txt1.Text & "' AND FIELD2 >= " & txt2.Text
'例子
' 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 DataGridView control and add it to the form.
Dim datagridview1 As New DataGridView()
datagridview1.AutoGenerateColumns = True
Me.Controls.Add(datagridview1)
' 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 DataGridView.
datagridview1.DataSource = source1
' The Filter string can include Boolean expressions.
source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'"
我正在使用 Visual Studio 10,使用 Oracle 数据库在 VB 中编程。 我需要使用 2 个变量对 DataGridView 进行筛选。到目前为止的代码如下所示:
TableBindingSource1.Filter = "[FIELD1] = '" & TextBox1.Text & "'"
DataGridView1.Refresh()
如何在此示例中插入 FIELD2 和 Textbox2,使两个过滤器一起工作?非常感谢。
可能是这样的:
Me.BindingSource.Filter = "FIELD1= '" & txt1.Text & "' AND FIELD2 >= " & txt2.Text
'例子
' 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 DataGridView control and add it to the form.
Dim datagridview1 As New DataGridView()
datagridview1.AutoGenerateColumns = True
Me.Controls.Add(datagridview1)
' 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 DataGridView.
datagridview1.DataSource = source1
' The Filter string can include Boolean expressions.
source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'"