We help IT Professionals succeed at work.

Search All using BindingSource Filter?

Gary Samuels
Gary Samuels asked
on
1,370 Views
Last Modified: 2008-01-09
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
Comment
Watch Question

Commented:
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
Gary SamuelsPlant Manager

Author

Commented:
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.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gary SamuelsPlant Manager

Author

Commented:
That's it! Thank you.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.