Search code examples
c#datagridviewcolumn

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;
    }
}

Solution

  • 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];
        }
    }