3
Contributors
2
Replies
18
Views
3 Years
Discussion Span
Last Post by mridul.ahuja
0

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
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.