如果在 vb.net 中找不到代码,则希望事件在带有 MessageBox 的文本框中而不是 gridview 过滤器状态中

发布于 2025-01-18 23:53:06 字数 817 浏览 1 评论 0原文

如果找不到代码,我想显示 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

view1view2

I want to appear MessageBox and not gridview filter state if code is not found.

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

view1
view2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2025-01-25 23:53:06

在其他内部添加另一个if语句,然后检查source1是否有行,如果行< = 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

Add another if statement inside the else then check if the source1 has rows, if rows <= 0 then clear the filter and the textbox.

UPDATED

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文