Question Search multiple columns

kasteel

Well-known member
Joined
May 29, 2009
Messages
50
Programming Experience
10+
Hi

Using the code below I can search my datagrid by filtering / searching one column.

How can I search my datagrid based on criteria from multiple columns?

Any help appreciated. :)

VB.NET:
        Sheet1DataGridView.DataSource = PgsaDataSet.Sheet1
        Dim strName As String
        strName = TextBox3.Text
        PgsaDataSet.Sheet1.DefaultView.RowFilter = String.Format("LastName Like '{0}%'", strName.Trim)
 
Use the AND/OR operators to combine multiple expressions as filter, this is common SQL syntax as in the WHERE part. In the help for RowFilter property it says "See the Expression property of the DataColumn class for more information.". Now click the Expression link and scroll down to the Operators part and you'll see what I mean.
 
Hi

Thanks for the reply.

I was able to do that with one cloumn.

Still can't seem to get the multiple column search to work though. (Example: 3 text boxes searching 3 columns.) It is not allowing me to do an AND/OR.
 
How is it not allowing you?
 
VB.NET:
PgsaDataSet.Sheet1.DefaultView.RowFilter = String.Format("LastName Like '{0}%' Or Column2 Like '{1}%' Or Column3 Like '{2}%'", strName.Trim, str2, Str3)
 
Its what JH described, I just wanted to see if that was how you were coding it since you said it still wasnt working.
 
Back
Top