This can be done easily with a CurrencyManager and DataViews.
I typically do this in the DataGridView's MouseUp event, using global objects:
First, define the CurrencyManager and a DataRowView globally:
Dim cmMainGrid As CurrencyManager
Dim drvMain As DataRowView
Also, create DataViews of the tables for the 2 sub-grids:
Dim dvGrid2 As DataView
Dim dvGrid3 As DataView
And, bind the DataViews to the appropriate DataTables:
dvGrid2 = DataTable2.DefaultView
dvGrid3 = DataTAble3.DefaultView
Use the DataViews as the DataSource of the two sub-grids.
Now, the main grid's MouseUp event handler:
Private Sub DataGridView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp
Dim hti As DataGridView.HitTestInfo 'define a HitTestInfo object to get the row clicked
hti = DataGridView1.HitTest(e.X, e.Y)
'check if the
If hti.RowIndex < DataGridView1.Rows.Count And hti.RowIndex > -1 Then
DataGridView1.Rows(hti.RowIndex).Selected = True
cmMainGrid = DataGridView1.BindingContext(DataTable1) 'note: use the name of the table you have bound to the grid
drvMain = cmPrinter.Current 'get a DataRowView of the currently selected row
'Filter the DataView for Grid2
dvGrid2.RowFilter = "Field1=" & drvMain.Item("Field1Key") 'dvGrid2 will only show data that matches the RowFilter
cmMainGrid = Nothing
drvMain = Nothing
dvGrid2.RowFilter = "Field1=-9999" 'use a value that will never return any rows in the filter
dvGrid3.RowFilter = "Field1=-9999" 'use a value that will never return any rows in the filter
DataGridView2.DataSource = Nothing
DataGridView3.DataSource = Nothing
Set up a MouseUp event handler for the second grid, similar to the one for the first grid, and use it to set the RowFilter for the third grid.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!