Reputation: 1371
I am binding my grid as such:
dataGridView1.DataSource = new BindingSource();
dataGridView1.DataSource = tableData;
(tableData is an ArrayList of custom objects)
The dataSource is getting updated very often (the file it is reading from gets updated about every 2 ms). So when I am scrolling, the scrollbar will jump to it's original position upon a refresh. I refresh like this:
((CurrencyManager)dataGridView1.BindingContext[tableData]).Refresh();
(this happens once every ~1 second)
How can I scroll without the scroll bar resetting every time the datagridview gets refreshed?
Upvotes: 3
Views: 13182
Reputation: 5899
I know it's been a while since you posted this question but I just ran into this kind of issue myself. One thing to check is to be sure you are not setting the CurrentCell property when your grid updates
Code such as the following will cause your scroll position to reset. You are telling it to view a particular row, and the first cell in that row.
YourGrid.CurrentCell = YourGrid[0, row];
Hope this helps.
DC
Upvotes: 0
Reputation: 3917
Take a look at this. Although the question is about Winforms DataGrid, the answer is applies to DataGridView. You need to store FirstDisplayedScrollingRowIndex before the reload and restore it after.
Upvotes: 5