Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

VS 2010 Datagridview Search through all Columns and Rows?

$
0
0
Is there a way to search all columns and rows in a datagridview? My goal is to have a Search Textbox and Find button. User will enter search string in the textbox and press the find button to search. If found the row will be selected. It would be nice if the button will also have the capability to find next.

Right now I have this code below. It can only search for a specific column in the datagridview. It would be nice if it can traverse all columns.

Code:

    Private Function FindString(ByVal strSearchString As String, ByVal strFields As String) As Boolean

        dgvDisbursements.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        dgvDisbursements.ClearSelection()

        Dim intCount As Integer = 0

        For Each row As DataGridViewRow In dgvDisbursements.Rows
            If InStr(1, dgvDisbursements.Rows(intCount).Cells(strFields).Value.ToString, strSearchString, CompareMethod.Text) Then
                dgvDisbursements.Rows(intCount).Selected = True
                FindString = True
                Exit Function
            End If
            intCount += 1
        Next row

        FindString = False

    End Function


Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>