Hi everyone,

If anyone knows how to make a automatuic search through datagid?
for instance i've a list of data which polulate in datagrid(Grid master), another set of data(one at a time) caputres from registry folder to compare against the exsisting datagird (Grid master). When the the match is found this data will be saved in the database. Question is how to make this work automatically. I could do this manually as user need to select the data from combobox and hit search button. Any help guys. Appriciated in advance.

Recommended Answers

Search through datagridview from combobox data :

        For i As Integer = 0 To DataGridView1.Rows.Count - 2
            For j As Integer = 0 To Me.DataGridView1.Rows(i).Cells.Count - 2
                If DataGridView1.Item(j, i).Value.ToString().Contains(ComboBox1.Text) Then
                    DataGridView1.Rows(i).Cells(j).Selected = True
                    DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(j)
                End If
            Next
        Next i
Jump to Post

All 2 Replies

Search through datagridview from combobox data :

        For i As Integer = 0 To DataGridView1.Rows.Count - 2
            For j As Integer = 0 To Me.DataGridView1.Rows(i).Cells.Count - 2
                If DataGridView1.Item(j, i).Value.ToString().Contains(ComboBox1.Text) Then
                    DataGridView1.Rows(i).Cells(j).Selected = True
                    DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(j)
                End If
            Next
        Next i

For automatic searching,you can put the entire searching code in the TextChanged event of the textbox.

Private Sub TextBox_TextChanged(sender As Object, _ 
  e As EventArgs) Handles TextBox.TextChanged

    For i As Integer = 0 To DataGridView1.Rows.Count - 2
      For j As Integer = 0 To Me.DataGridView1.Rows(i).Cells.Count - 2
        If DataGridView1.Item(j, i).Value.ToString().Contains(ComboBox1.Text) Then
          DataGridView1.Rows(i).Cells(j).Selected = True
          DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(j)
        End If
      Next
    Next i
 End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.