Datagridview SelectionChanged row-based event

I have a DataGridView in a tab. When the user clicks on the line, a second DGV appears. Each row is associated with its own DGV filled with data. I want, when the user goes from one row to another, the DataGridView changes. So far I have tried the SelectionChanged event, but I do not want to restart the DGV in case the user clicks on a separate cell in the same row. Any help would be greatly appreciated.

void dgv1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = dgv1.Rows[e.RowIndex].Index; if (dgv1 == null) return; if (dgv1.Rows[e.RowIndex].Cells[rowIndex].Selected == true); { dgv2.Size = new Size(dgv2.Width + 800, dgv2.Height); dgv2.Location = new Point(0, 500); tp.Controls.Add(dgv2); Console.WriteLine("Row clicked"); } } 

-Tatiana

+6
source share
2 answers
  int curRow = -1; private void dgv1_SelectionChanged(object sender, EventArgs e) { if (dgv1.CurrentRow.Index != curRow) { curRow = dgvPatientDetail.CurrentRow.Index; } 
+11
source

I know that the post is old, but for other readers: Customization ..

DataGridView1.FullRowSelect = true

should solve this problem.

+1
source

All Articles