Search Inside Datagridview Winforms VB.NET

If txtName.Text <> "" Then
            Dim s As String = txtName.Text.Trim
            dgv.ClearSelection()
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            Dim someText As String = s
            Dim gridRow As Integer = 0
            Dim gridColumn As Integer = 0
            For Each Row As DataGridViewRow In dgv.Rows
                For Each column As DataGridViewColumn In dgv.Columns
                    Dim cell As DataGridViewCell = (dgv.Rows(gridRow).Cells(gridColumn))
                    If cell.Value.ToString.ToLower.Contains(someText.ToLower) Then
                        ‘cell.Style.BackColor = Color.Yellow
                        dgv.FirstDisplayedScrollingRowIndex = Row.Index
                        dgv.Item(cell.ColumnIndex, cell.RowIndex).Selected = True

                    End If
                    gridColumn += 1
                Next column
                gridColumn = 0
                gridRow += 1
            Next Row
        Else
            dgv.ClearSelection()
        End If

here dgv is datagridview and txtname is the textbox

when you started to type letters in txtname the rows inside the datagridview will be selected based on the letters typed .

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.