Reputation: 126
I'm trying to get a search box to search more than one column on a datagrid. Currently this is what I've got:
Private Sub txt_search_TextChanged(sender As System.Object,
e As System.EventArgs) Handles TextBox1.TextChanged
Me.CriticalBindingSource.Filter = String.Format("{0} LIKE '{1}%'",
Database29DataSet.Critical.AddressColumn, TextBox1.Text)
End Sub
This works perfectly to search for 1 column (in this case AddressColumn) but I'm struggling to make it search for more than one column. I tried using a simple if statement and did not work.
Upvotes: 2
Views: 184
Reputation: 4262
You could try multiple OR statements if you have a fixed number of columns
eg:
Me.CriticalBindingSource.Filter = String.Format(
"{0} LIKE '{1}%' OR {2} LIKE '{1}%'",
Database29DataSet.Critical.AddressColumn,
TextBox1.Text,
Database29DataSet.Critical.Column2)
Upvotes: 2