Windows Forms - Select DataGridView row based on ComboBox selection

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

In VB.net 2010 I have a Windows form with a ComboBox that contains my supplier names.
When I click on a supplier I want a row in my DataGridView to be selected. The first column or cell
of my DataGridView also contains this supplier name
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In ComboBox  Selected change event find the supplier name in the datagridview and if it matches set its cell to focus.
Most Valuable Expert 2012
Top Expert 2014
Commented:
Combobox_SelectedIndexChanged

For i As Integer = 0 to dgv.Rows.Count
      If dgv.Rows(i).Cells(0).Value = combobox1.Text Then
         dgv.CurrentCell = dgv.Rows(i).Cells(0)
      End If
Next
Most Valuable Expert 2012
Top Expert 2014
Commented:
Minor revision

For i As Integer = 0 to dgv.Rows.Count
      If dgv.Rows(i).Cells(0).Value = combobox1.Text Then
         dgv.CurrentCell = dgv.Rows(i).Cells(0)
         Exit For
      End If
Next
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial