當我清除表單中的搜索框時,表格顯示相同的資訊(我希望表格顯示原始資訊,無需任何查詢)。
代碼:
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
uj5u.com熱心網友回復:
如果我正確閱讀了這個問題,那么您似乎在說:
- 您添加一個搜索詞
TextBox14,然后將其應用于 ,然后按預期CustomerInfo1BindingSource.Filter過濾CustomerInfo1DataGridView - 您從中洗掉搜索詞
TextBox14并再次單擊該按鈕 - 過濾
CustomerInfo1DataGridView后保持不變,而不是顯示所有內容
如果是這種情況,我可以看到代碼流并不完全符合您的期望。將其更改為:
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
與您的代碼一樣,該行CustomerInfoBindingSource.Filter = Nothing沒有被擊中,因為TextBox14. 相反,它呼叫了這個NotFound()我們不知道的方法,然后退出了該方法。
可能還值得閱讀官方檔案。您可以在 a 上呼叫RemoveFilterBindingSource:
CustomerInfoBindingSource.RemoveFilter()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426203.html
下一篇:如何用2個不同的鍵決議Json?
