如果找不到代碼,我想出現 MessageBox 而不是 gridview 過濾器狀態。
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If TextBox2.Text = "" Then
source1.Filter = ""
Me.DataGridView1.Refresh()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE like '' '" & TextBox2.Text & "' '' "
Me.DataGridView1.Refresh()
End If
End If
End Sub

uj5u.com熱心網友回復:
if statement在 else 中添加另一個然后檢查是否source1有行,如果 rows <= 0 然后清除過濾器和文本框。
更新
Dim source1 As New BindingSource()
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox2.KeyDown
If TextBox2.Text = "" Then
source1.Filter = ""
Me.DataGridView1.Refresh()
Else
If e.KeyCode = Keys.Enter Then
source1.Filter = "CODE like '' '" & TextBox2.Text & "' '' "
' If Else Statement to determine the count of your bindingsource
' Check the results, if result is less than or equal to 0
' then prompt messagebox and clear the source filter
If source1.count <= 0
source1.Filter = ""
TextBox2.Clear()
MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
End If
Me.DataGridView1.Refresh()
End If
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/455650.html
上一篇:設計模式之中介者模式
