Finding a String in a datagrid view.
Posted on 2007-10-16
I have this code to search a datagridview:
Private Sub FindToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
SearchString = UCase(Trim(InputBox("Search for", "Find")))
Dim datarowcount = DataGridView1.RowCount
Dim x = 0
For x = 0 To datarowcount - 1
If DataGridView1.Item(1, x).Value.ToString = SearchString.ToString Then
DataGridView1.Item(1, x).Selected = True
DataGridView1.FirstDisplayedScrollingRowIndex = x
The field it is searching is an URL field. I did a test and if there are no charachers just numbers for example all the URL Field had was 1 through 12 and I do a search for 9 it will go to it, but if I have any text whatsoever it will not find any query I put in. I even did a mix of numbers and characters it would only find the file that had the lone number in it.