Just use the Cell Click event of one of the grid
You can add or make changes according to your output:
Consider that i have Two datagridView with same rows and columns and im dynamically adding rows and columnsto both the grids.
private void btnAdd_Click(object sender, EventArgs e)
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
dataGridView2.ColumnCount = 3;
dataGridView2.Columns[0].Name = "Product ID";
dataGridView2.Columns[1].Name = "Product Name";
dataGridView2.Columns[2].Name = "Product Price";
string[] row1 = new string[] { "1", "Product 1", "1000" };
dataGridView2.Rows.Add(row);
row1 = new string[] { "2", "Product 2", "2000" };
dataGridView2.Rows.Add(row);
row1 = new string[] { "3", "Product 3", "3000" };
dataGridView2.Rows.Add(row);
row1 = new string[] { "4", "Product 4", "4000" };
dataGridView2.Rows.Add(row1);
}
Secondly I have the CellClick Event of My first DataGrid :
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int rowindex = dataGridView1.Rows[e.RowIndex].Index;
int columnindex = dataGridView1.Columns[e.ColumnIndex].Index;
dataGridView2.Rows[rowindex].Cells[columnindex].Selected = true;
}
So when i click one content of my first grid the same cell gets selected in the second grid .
You can add your code in CellClick Event of dataGrid .