views:

2253

answers:

1

How do I programmatically set the record pointer in a C# DataGridView?

I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row.

+1  A: 

To change the active row for the datagrid you need to set the current cell property of the datagrid to a non-hidden non-disabled, non-header cell on the row that you have selected. You'd do this like:

dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];

Making sure that the cell matches the above criteria. Further information can be found at:

http://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx

Wolfwyrd