我必须使用textbox过滤datagridview。下面的代码用于填充db类的gridview.getdata函数返回数据表。在Windows应用程序中的DataGridview中搜索VB.NET
我没有使用gridview的datasource属性,而是使用循环提交gridview。
我可以使用datasource属性和dataview进行搜索,但我没有直接从datasource属性填充datagridview。
Sub griddesgn()
DataGridView1.Columns.Clear()
DataGridView1.Rows.Clear()
DataGridView1.Columns.Add("crime", "crime")
DataGridView1.Columns.Add("actname", "actname")
DataGridView1.Columns.Add("section", "section")
DataGridView1.Columns.Add("description", "description")
End Sub
Private Sub TEST_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
griddesgn()
Dim DBOBJ As New db
Dim DTT As DataTable = DBOBJ.getdata("SELECT crime,actname,section,description from natureofcomplaint_women")
If DTT.Rows.Count > 0 Then
For i As Integer = 0 To DTT.Rows.Count - 1
DataGridView1.Rows.Add()
DataGridView1.Rows(i).Cells("crime").Value = DTT.Rows(i).Item("crime") & ""
DataGridView1.Rows(i).Cells("actname").Value = DTT.Rows(i).Item("actname") & ""
DataGridView1.Rows(i).Cells("section").Value = DTT.Rows(i).Item("section") & ""
DataGridView1.Rows(i).Cells("description").Value = DTT.Rows(i).Item("description") & ""
Next
End If
End Sub
对不起,这对我来说还不清楚。你在标题中提到搜索,但你(隐含地)讨论在你的问题中使用'ItemsSource'。 –
我编程地填充数据在gridview中使用for循环从datatable dt由getdata函数返回。现在数据应该过滤,只要我开始在显示的文本框中键入。它说... – user3449614
绑定DataTable到DataGridView与BindingSource 。然后,使用BindingSource的Filter属性。 – Graffito