C # Scrollbars keep reset when DataGridView is refreshed

I am linking my grid as such:

dataGridView1.DataSource = new BindingSource();

dataGridView1.DataSource = tableData;

(tableData is an ArrayList for custom objects)

The data source is updated frequently (the file it reads is updated approximately every 2ms). So when I scroll, the scrollbar will jump back to its original position when updated. I am updating as follows:

((CurrencyManager)dataGridView1.BindingContext[tableData]).Refresh();

(this happens once every 1 second)

How to scroll without resetting the scrollbar on every datagridview refresh?

+3


source to share


2 answers


Take a look. While the question is about Winforms DataGrid, the answer is specific to DataGridView. You need to save FirstDisplayedScrollingRowIndex before reboot and restore it after.



+5


source


I know it has been a while since you posted this question, but I just ran into a similar question. Need to check that you are not setting the CurrentCell property when updating the grid

Code like the following will cause your scroll position to be reset. You tell him to view a specific row and the first cell in that row.

YourGrid.CurrentCell = YourGrid[0, row];

      



Hope it helps.

DC

0


source







All Articles