Gary Samuels
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(B yVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchBox.TextChanged
With Me.myBindingSource
.Filter = "Column1 LIKE '%" & txtSearchBox.Text & "%'"
End With
End Sub
Private Sub txtSearchBox_TextChanged(B
With Me.myBindingSource
.Filter = "Column1 LIKE '%" & txtSearchBox.Text & "%'"
End With
End Sub
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's it! Thank you.
Dim toFind As String = "'%" & txtSearchBox.Text & "%'"
With Me.myBindingSource
.Filter = "Column1 LIKE " & toFind " OR Column2 LIKE " & toFind & " OR Column3 LIKE " & toFind
End With
Roger