Search code examples
vb.netsearchdatagridviewfilterrowfilter

search for partial match over multiple columns at sametime datagridview


I have a datagridview and i am surching in it ussing the following method

dvdonors.RowFilter = "STATUS = '" & TextBox1.Text & "' or PROJECT = '" & TextBox1.Text & "'" 'works compleate match

This allows me to search in either Status or project nice, but it rquiers a total match for a valid resualt.

the following code allows the user to search based upon a partial match..

dvdonors.RowFilter = String.Format("{0} LIKE '{1}%'", "STATUS", TextBox1.Text)

owever the problem is that this onlhy searches for a partial match in a specifide column.

The idea is to search for partial match over bothe columns so I have tryed to combine the codes as follows but this obviously dosnt work. Could somebody please assist?

dvdonors.RowFilter = String.Format("PROJECT LIKE '%{0}%' AND STATUS LIKE '%{1}%'", TextBox1.Text)

Solution

  • You are using AND which if what you are looking for does not exist in both columns you will not get anything. Either change it to OR or try this...

     dvdoners.RowFilter = "PROJECT LIKE '%" & Textbox1.Text & "%'" & " OR STATUS LIKE '%" & Texbox1.Text & "%'"
    

    Also your second filter is looking for a field 1 you want 0 if using String.Format.