Hi All,
I want to search specific range of rows in datagridview. I want to search the entire third row of my datagridview. How can I do that?
Here's my current code:
Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
For Each row As DataGridViewRow In DataGridView.Rows
' Skip the new row
If row.IsNewRow Then Exit For
' Loop through all the cells in the current row
For Each cell As DataGridViewCell In row.Cells
' Skip non-text cells
Try
If cell.GetType IsNot GetType(DataGridViewTextBoxCell) Then Continue For
' Search for our matching text
If cell.Value.ToString.Contains(findBox.Text) Then
' Select the cell if we have a match
DataGridView.CurrentCell = cell
Exit Sub
Else
End If
Catch ex As Exception
MessageBox.Show("String NOT found.", "Search for: " & findBox.Text)
End Try
Next
Next
' If we get to this point, we didn't find anything
MessageBox.Show("String NOT found.", "Search for: " & findBox.Text)
End Sub
Thanks in advance.