First you need to expose the DataGridView Control on both MdiChild Forms so the MdiParent Form can access them: so the first MdiChildForm's code might look like this:
public DataGridView f1DGView { get; set; }
private void MdiChildForm1_Load(object sender, EventArgs e)
{
f1DGView = dataGridView1;
}
The second MdiChildForm's code will be identical, except for the DataGridView name.
Then, in the MdiParentForm:
int currentDGVRow;
private MdiChildForm1 = new MdiChildForm1();
private MdiChildForm2 = new MdiChildForm2();
private void MdiParent_Load(object sender, EventArgs e)
{
MdiChildForm1.MdiParent = this;
MdiChildForm2.MdiParent = this;
MdiChildForm1.Show();
MdiChildForm2.Show();
MdiChildForm2.Hide();
MdiChildForm1.f1DGView.CellDoubleClick += f1DGView_CellDoubleClick;
MdiChildForm2.f2DGView.CellDoubleClick += f2DGView_CellDoubleClick;
}
private void f1DGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
currentDGVRow = e.RowIndex;
button1.BackColor = Color.Ivory;
button2.BackColor = Color.Snow;
MdiChildForm1.Hide();
MdiChildForm2.Show();
MdiChildForm2.f2DGView.Rows[currentDGVRow].Selected = true;
}
private void f2DGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
currentDGVRow = e.RowIndex;
button1.BackColor = Color.Snow;
button2.BackColor = Color.Ivory;
MdiChildForm2.Hide();
MdiChildForm1.Show();
MdiChildForm1.f1DGView.Rows[currentDGVRow].Selected = true;
}