DataGridView Preserve Selected Index and Scroll Position after update and reload

sokol picture sokol · Jan 13, 2016 · Viewed 8.9k times · Source

I have some problem, don't now how to preserve the scroll position in a DataGridView.

I have over 1000+ rows and scrolling back to edited row is painful. How can I preserve the scroll position and scroll to the edited row after refreshing data?

Answer

OhBeWise picture OhBeWise · Jan 13, 2016

Save the row index, do your refresh, then set the FirstDisplayedScrollingRowIndex property.

int index = dataGridView1.CurrentRow.Index;

/*
 * Your Refresh Code
 */

dataGridView1.FirstDisplayedScrollingRowIndex = index;