When I clear the search box in the form, the table shows the same info (I want the table to show the original one, without any query).
Code:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TextBox14.Text = "" Then
Call NotFound()
Exit Sub
Else
CustomerInfo1BindingSource.Filter = "(Convert(ID, 'System.String') LIKE '" & TextBox14.Text & "')" &
"OR (CustomerName LIKE '" & TextBox14.Text & "') OR (CustomerNumber LIKE '" & TextBox14.Text & "')" &
"OR (OrderDate LIKE '" & TextBox14.Text & "')"
If CustomerInfo1BindingSource.Count <> 0 Then
With CustomerInfo1DataGridView
.DataSource = CustomerInfo1BindingSource
End With
Else
MsgBox("Not Found!")
CustomerInfoBindingSource.Filter = Nothing
End If
End If
End Sub
If I've read the question correctly it appears that you're saying this:
TextBox14
which is then applied to the CustomerInfo1BindingSource.Filter
and in turn that filters CustomerInfo1DataGridView
as expectedTextBox14
and click the button againCustomerInfo1DataGridView
remains untouched rather than showing everythingIf that is the case I can see that code flow isn't exactly what you're expecting. Change it to be something like:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TextBox14.Text = "" Then
CustomerInfoBindingSource.Filter = Nothing
MsgBox("Not Found!")
Else
CustomerInfo1BindingSource.Filter = "(Convert(ID, 'System.String') LIKE '" & TextBox14.Text & "')" &
"OR (CustomerName LIKE '" & TextBox14.Text & "') OR (CustomerNumber LIKE '" & TextBox14.Text & "')" &
"OR (OrderDate LIKE '" & TextBox14.Text & "')"
If CustomerInfo1BindingSource.Count <> 0 Then
With CustomerInfo1DataGridView
.DataSource = CustomerInfo1BindingSource
End With
End If
End If
End Sub
As it stands with your code the lineCustomerInfoBindingSource.Filter = Nothing
is not being hit because there is no search term in TextBox14
. Instead it's calling this NotFound()
method which we don't have visibility of, and then exiting the method.
It might be worth also reading up on the official documentation. You can call RemoveFilter on a BindingSource
:
CustomerInfoBindingSource.RemoveFilter()