Supposing that your are using _dataTable1
to get your table, and your filter name is Filter1
you can do as follow:
Private Sub txtSearchbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchbox.TextChanged
Dim Filter1 As String
Filter1 = "EmployeeNo LIKE '%" & txtSearchbox.Text & "%' OR " & _
"User LIKE '%" & txtSearchbox.Text & "%' OR " & _
"Item LIKE '%" & txtSearchbox.Text & "%'"
' Sort bonus ;)
Dim Sort1 As String = " User ASC"
_dataTable1.DefaultView.RowFilter = Filter1
_dataTable1.DefaultView.Sort = Sort1
'Bind your DataGridView1 to your _dataTable1
DataGridView1.DataSource = _dataTable1
End Sub
Edit:
Supposing that previously you declared your _dataTable1
public and already loaded the data inside with your query
Public _dataTable1 As New DataTable()
Public Sub New()
' Do you query here
Dim query As string = "Select [EmployeeNo], [User], [Item] "
Using con as oledbconnection = new oledbconnection("datasourceofdatabase")
....
....
If dt1.Rows.Count > 0 Then
_dataTable1 = dt1
....
....
End Sub
I suggest you to take a look to the following : VB.NET DataGridView binding - Sql Server there is simple example that work very well and easy to understand. Not only for DataGridView but for all VB.net.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…