Link to home
Start Free TrialLog in
Avatar of Gary Samuels
Gary SamuelsFlag for United States of America

asked on

Search All using BindingSource Filter?

I have a Windows Form which contains 3 text boxes. The text boxs are bound to a dataset containing Column1, Column2 and Column3. I have added a 4th text box named txtSearchBox. Using the code below I can filter the dataset by any single column. What I would like to do is create a Search All feature.  Somthing like:  .Filter = "Column1 OR Column2 OR Column3 LIKE '%" & txtSearchBox.Text & "%'"   , of course this doesn't work. Any ideas on how to search/filter a dataset on all columns?



 Private Sub txtSearchBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchBox.TextChanged

        With Me.myBindingSource
            .Filter = "Column1 LIKE '%" & txtSearchBox.Text & "%'"
        End With

    End Sub
Avatar of Sancler
Sancler

Try this

        Dim toFind As String = "'%" & txtSearchBox.Text & "%'"

        With Me.myBindingSource
            .Filter = "Column1 LIKE " & toFind " OR Column2 LIKE " & toFind & " OR Column3 LIKE " & toFind
        End With

Roger
Avatar of Gary Samuels

ASKER

No sorry, I got the error: End of statement expected, just before the first OR condition.

I changed it to:
.Filter = "Column1 LIKE 'toFind'  OR Column2 LIKE 'toFind' OR Column3 LIKE 'toFind' "

and:
.Filter = "Column1 LIKE '& toFind'  OR Column2 LIKE '& toFind' OR Column3 LIKE '& toFind' "

Both ran but returned no results on the search. As soon as a character is entered all recorders are filtered out. I'm skeptical about using the OR condition in the Filter. What I'm guessing is that I'll have to create another dataset and fill it with the results of the search on each column. Not sure how to handle duplicate records yet.
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's it! Thank you.