I need your assistance to filter the values in Datagrid by using text box.
Whenever the I type the value in Text-box, it filters the values in data grid without using any database connectivity. I got the below coding but it is not working and it is not filtering anything.
Please provide me the code to do the search the content in Data grid.
Public Sub txtsearch_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtsearch.TextChanged
Dim Flag As Boolean
If Flag = True Then
dgDisplay.ClearSelection()
For Each row As DataGridViewRow In dgDisplay.Rows
For Each cell As DataGridViewCell In row.Cells
If Not IsNothing(cell.Value) Then
If cell.Value.ToString.StartsWith(txtsearch.Text, StringComparison.InvariantCultureIgnoreCase) Then
cell.Selected = True
dgDisplay.CurrentCell = dgDisplay.SelectedCells(0)
'Exit For
End If
End If
Next
Next
Else
If txtsearch.Text = "" Then
dgDisplay.Rows(0).Selected = True
End If
End If
End Sub
Whenever the I type the value in Text-box, it filters the values in data grid without using any database connectivity. I got the below coding but it is not working and it is not filtering anything.
Please provide me the code to do the search the content in Data grid.
Public Sub txtsearch_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtsearch.TextChanged
Dim Flag As Boolean
If Flag = True Then
dgDisplay.ClearSelection()
For Each row As DataGridViewRow In dgDisplay.Rows
For Each cell As DataGridViewCell In row.Cells
If Not IsNothing(cell.Value) Then
If cell.Value.ToString.StartsWith(txtsearch.Text, StringComparison.InvariantCultureIgnoreCase) Then
cell.Selected = True
dgDisplay.CurrentCell = dgDisplay.SelectedCells(0)
'Exit For
End If
End If
Next
Next
Else
If txtsearch.Text = "" Then
dgDisplay.Rows(0).Selected = True
End If
End If
End Sub