【问题标题】:Vb.net DataGrid View Find TextVb.net DataGrid 查看查找文本
【发布时间】:2014-06-11 04:39:39
【问题描述】:

如何通过快捷键(Shift+F)在 dataGridView 中找到用户搜索的字符串,以及 Visual Studio 2005 Windows 应用程序中 DataGridView 的快捷键处理程序事件是什么。

【问题讨论】:

    标签: vb.net


    【解决方案1】:
    Public Class Form1
    
      Sub New()
    
        ' This call is required by the designer.
        InitializeComponent()
    
        ' Add any initialization after the InitializeComponent() call.
        Dim dtb As New DataTable
        dtb.Columns.Add(New DataColumn("Col1"))
        dtb.Columns.Add(New DataColumn("Col2"))
        dtb.Columns.Add(New DataColumn("Col3"))
        dtb.Columns.Add(New DataColumn("Col4"))
        dtb.Rows.Add("apple banana", "carrot date", "eggplant fig", "guava horseradish")
        dtb.Rows.Add("ant beetle", "cricket dung beetle", "earwig fly", "grasshopper horntail")
        DataGridView1.DataSource = dtb
    
      End Sub
    
      Private Sub DataGridView1_KeyUp(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyUp
        If e.KeyData = (Keys.Control Or Keys.F) Then
          Dim strSearch As String = InputBox("Enter search term", , "fig")
    
          For intRow As Integer = 0 To DataGridView1.Rows.Count - 1
            For intCol As Integer = 0 To DataGridView1.Columns.Count - 1
              If DataGridView1.Rows(intRow).Cells(intCol).Value.ToString.Contains(strSearch) Then
                DataGridView1.ClearSelection()
                DataGridView1.Rows(intRow).Cells(intCol).Selected = True
                Exit Sub
              End If
            Next intCol
          Next intRow
    
        End If
      End Sub
    End Class
    

    【讨论】:

    • 不客气。如果您能将我的答案标记为解决方案(如果有效),我将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多