We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to make CurrentRowIndex the Top row in datagrid.

Dear all, How do I make the CurrentRowIndex the Top row visible in a datagrid? Basically I need to scoll through my dataset by using buttons. (The next button gets the next 40 records from the db and appends them to the dataset. The first new row should be the top row in the dataset.) Hopefully I'm clear enough and "can be helped" ;-) Thanks

2 Replies

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

Live Chat Icon For mobile
Up arrow icon