How do i select a row in a dataGridView? (properly with keyboard)
I have the following code. When i refresh my datagrid the row select is still select (note i only have one select row at a time which is why selectIndex is one value and not a list).
The problem is when i move my arrowkey up or down it starts from the beginnin开发者_运维技巧g of the datagridview and not the row selected.
var ret = dataGridView1.Rows.Add(r.orderNo, r.link, r.status);
dataGridView1.Rows[ret].Tag = r;
if (r.id == selectIndex)
{
dataGridView1.Rows[ret].Selected = true;
}
This seems to solve your problem:
void SelectGridRow( int rowIndex )
{
_grid.Rows[ rowIndex ].Cells[ 0 ].Selected = true;
}
精彩评论