我在 TabPage 上有一个 DataGridView。当用户单击一行时,会出现第二个 DGV。每行都与其自己的 DGV 相关联,其中充满了数据。我想要的是当用户从一行转到另一行时,DataGridView 也会发生变化。到目前为止,我已经尝试了 SelectionChanged 事件,但我不希望 DGV 在用户单击同一行中的单独单元格时重新加载。任何帮助将不胜感激。
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");
}
}
-塔蒂亚娜
最佳答案
int curRow = -1;
private void dgv1_SelectionChanged(object sender, EventArgs e)
{
if (dgv1.CurrentRow.Index != curRow)
{
curRow = dgvPatientDetail.CurrentRow.Index;
}
关于c# - 基于行选择的Datagridview SelectionChanged事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21124831/