Link to home
Start Free TrialLog in
Avatar of David Megnin
David MegninFlag for United States of America

asked on

How to link two DataGridViews

On a Windows Form I have two DataGridViews, one for each of two related tables.  They are related on a common Key_ID field.  I want them to always stay linked on that Key_ID so that the selected rows stay in sync and if Key_ID is selected in on DataGridView the row with the same Key_ID is selected in the other DataGridView.

I'm currently using a ComboBox bound as follows to link them:
Data Source:  BindingSource1
Display Member:  Some Text
Value Member: Table1.Key_ID
Selected Value: Table2.Key_ID

The problem with this is that when I scroll down through the rows the textbox I have capturing the information I need is a row behind.  It displays the value from the row I have just left not the current row.  I have a SQL query run on the ComboBox.SelectedIndexChanged event.

I'd like to do away with the combobox entirely and just link the two DataGridView directly.  Any ideas?  
I'm using VB.NET in VS2005, .Net 2.0

Thanks.
David
ASKER CERTIFIED SOLUTION
Avatar of Babycorn-Starfish
Babycorn-Starfish
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Megnin

ASKER

Wonderful!  Exactly with I was looking for.

Thank you very much!

David