Programmatically setting the record pointer in a C# DataGridView
-
01-07-2019 - |
Question
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.
Solution
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:
OTHER TIPS
Try setting the focus of the DataGrid
first . Some thing like this
dataGridView1.Focus();
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];
This worked in my case, hope it helps you as well
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow