c# – 基于行选择的Datagridview SelectionChanged事件

前端之家收集整理的这篇文章主要介绍了c# – 基于行选择的Datagridview SelectionChanged事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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");
    }
}@H_403_3@ 
 

-Tatiana

解决方法

int curRow = -1;

    private void dgv1_SelectionChanged(object sender,EventArgs e)
    {
        if (dgv1.CurrentRow.Index != curRow)
        {
            curRow = dgvPatientDetail.CurrentRow.Index;        
        }@H_403_3@

猜你在找的C#相关文章