Hi guys, I have a datagrid which starts off blank and slowly gets populated as processes execute. It also refreshes every 5 seconds using the timer.

The problem I have is, after it refreshes it resets the view to the top of the list. So you may have scrolled down and selected the 20th item in the list, but after the refresh it's back to the top.

I tried the below code but I get an error because the grid is empty to start with and it can't get the index location.

Code:
i = HistoryDataGridView.CurrentRow.Index
 HistoryDataGridView.CurrentCell = HistoryDataGridView.Rows(i).Cells(1)
Error I get is:
Additional information: Object reference not set to an instance of an object

Whats the best way to handle this?

One other question, how do I get the datagrid to retain it's current position? If for example I have scrolled down 40 rows, how do I get it stay there after the refresh?