CB
Clay Burch
Syncfusion Team
June 20, 2002 08:09 AM UTC
There appears to be no TopRow property exposed in the DataGrid, and also no scroll command. The FAQ referenced below explains how you can write a method that returns the TopRow. This will not let you actually set the TopRow to some particular row though. But you can probably write a method that would do it based upon the idea that when you set a new CurrentCell, the DataGrid scrolls to make it visible.
Here's how you could use this idea. Set the currentcell to the row you want to be the toprow. Then check the actual toprow index. If it is less, we need to make the datagrid scroll up. If it is higher, we need to make the datagrid scroll down. To actually do the scrolling once the direction is known, just incrementally set higher (or lower) current cells until the toprow is on the row you desire. You would also probably want to sandwich this code between BeginUpdate and EndUpdate/Invalidate calls so the positioning appears cleaner without seeing the individual scrolls drawn.
Now I did not actually try this idea, so I am not sure what kinds of problems you might encounter.
George Shepherd's Windows Forms FAQ contains an entry entitled:
How do I find the top-left visible cell in a datagrid?
Check it out at:
http://www.syncfusion.com/faq/winforms/search/880.asp
CB
Clay Burch
Syncfusion Team
June 22, 2002 09:10 AM UTC
Here is a simple way to scroll the datagrid. It uses a protected member of the DataGrid, so you have to have a derived datagrid to use it.
George Shepherd's Windows Forms FAQ contains an entry entitled:
How do I programatically scroll the datagrid to a particular row?
Check it out at:
http://www.syncfusion.com/faq/winforms/search/895.asp