简体   繁体   中英

Datagridview SelectionChanged event based on row selection

I have a DataGridView on a TabPage. When the user clicks on a row, a second DGV appears. Each row is associated with its own DGV filled with data. What I want is for when the user goes from one row to another, the DataGridView changes too. So far I've tried the SelectionChanged event but I don't want the DGV to reload in the event that the user clicks on a separate cell in the same row. Any help would greatly be 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

    int curRow = -1;

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

I know the post is old but for others reading: Setting ..

DataGridView1.FullRowSelect = true

should resolve this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM