Doing something like this:
dataGridView1.CurrentCell = dataGridView1.Rows[index].Cells[0];
will only work if the first column is visible. If it is hidden, you will get an exception. It is safer:
var column = dataGridView1.CurrentCell != null ? dataGridView1.CurrentCell.ColumnIndex : dataGridView1.FirstDisplayedScrollingColumnIndex; dataGridView1.CurrentCell = dataGridView1.Rows[iNextHighlight].Cells[column];
This will reset the selection without scrolling if the target line is already on the screen. It also saves the current selection of columns, which may make a difference when you enable inline editing.
sgriffin May 27 '15 at 13:40 2015-05-27 13:40
source share