Search code examples
c#winformsdatagridviewscrollvirtualmode

How to change the row position of virtual mode DataGridView?


How to change the row position of virtual mode DataGridView?

I am using Windows Forms.


Solution

  • Marcus's answer is correct, but you may also need to set the DataGridView's current cell property...

    dgv.CurrentCell = dgv.Rows[0].Cells[0];
    

    I believe this will scroll the grid. Also, to be absolutely safe, you may want to add this before the other line of code...

    dgv.CurrentCell = null;
    

    This will ensure that if the row you want is already the active row but just scrolled out of view, it will scroll it back into view.