jmc
jmc

Reputation: 1729

Set DataGridView arrow to the selected row

How do I set the arrow to the selected row. I'm programatically selecting the rows based on the value of a combo box. Currently, only the row is highlighted and the arrow doesn't follow

foreach (DataGridViewRow row in dgv.Rows)
{
    if ((int)row.Tag == ma.ID)//ma.ID is the selected combo box value
    {
        row.Selected = true;
    }
}

Upvotes: 0

Views: 1572

Answers (1)

jhmt
jhmt

Reputation: 1421

You have to change CurrentCell like this. (This will also change CurrentRow)

foreach (DataGridViewRow row in dgv.Rows)
{
    if ((int)row.Tag == ma.ID)//ma.ID is the selected combo box value
    {
        row.Selected = true;
        dgv.CurrentCell = row.Cells[0];
    }
}

Upvotes: 2

Related Questions