I have a datagridview on the Windows Form in c#. I am updating and filling the table adapter on the cell event. The problem is that When I go to lower half of the datagrid which is not visible until I scroll down, as I click any cell, the table adapter is filled and updated and the pointerpoints to the very first row. Any suggestion on how to fix it. I have a ideas to record the top row of the datagridview that is visible and set the pointer to that row. But how to do it?
A:
Before the fill happens, save the current cell:
DataGridViewCell selectedCell = dgv.CurrentCell;
Then after the fill, set it back:
dgv.CurrentCell = selectedCell;
If you don't care which cell was selected but just want to scroll the view back to where it was before the fill, you can use the FirstDisplayedCell
property instead.
I believe these will work but I haven't used them in your exact scenario (which sounds kinda funky).
Incidentally, there a lot of events on the DataGridView, which gives great flexibility, but you have to read the docs carefully to understand all your options.
Charles
2010-03-27 19:35:07