开发者

How to set the pointer to the current row in the Datagridview in C#

I have a datagridview on th开发者_高级运维e 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜