Hi,
I use a wingrid which auto refreshes every 5 seconds.The problem that I face is when the user scrolls down the grid, suddenly the grid refreshes and moves back up to the top.I want the grid to stay in the same scroll area after refreshing.I set the the first row as active row after every refresh.
So how to save the current scroll position and load the same back after refresh?Or can anyone suggest a better solution?
Thanks,
Abja
Hi Mike,
Thanks for the reply.
I managed to solve the scrolling problem.I set the ActiveRowScrollRegion.ScrollPosition to the old one after refresh .Also I used the RowScrollRegions[0].ScrollRowIntoView(row) function.The row is the second visible row from the ActiveScrollRegion as the first row is the filter row.
Regds,
Hi Abja,
Hm. Maybe you could use the ScrollRowIntoView method. This is also on the ActiveRowScrollRegion. I think this method might have an overload that allows you to specify that you want the row scrolled to the top, but I could be wrong.
Also note that the DisplayLayout does not include any row or cell settings. So it will take care of the column width (since columns are on the band and thus part of the data structure), but it will not include the expanded or selected state of the rows.
Thanks for the reply.I managed to reload the state information by using the displaylayout.save() and load functions.But what I want to set is the active scroll region same as the old.I tried as you said.But the grid's FirstRow property on the ActiveRowScrollRegion is always the filter row as I have a filter row on the top.The active scroll region actually changes from the second row only. What I have to set is the second row.I am able to get the second row from the visible rows collection and i can keep the ID or some other value for finding the same row after refresh.
But I dont know which property I need to set ? Or plz advice me how to handle this?
Thanks in advanz
You are going to lose more than just the scroll position. If you are resetting your data source, you will lose all state information in the grid. This includes row height, expanded state, column widths, selected rows, etc.
So you are probably better off not resetting the data source if you can avoid it.
The above line of code will only work in CardView, so that's probably not the right way to do. What you want is the FirstRow property on the ActiveRowScrollRegion. You can set this to the row you want at the top.
However, you can't store the row you had before the reset and then use the same row to restore the position, because the rows will all be destroyed and a whole new set of rows created. So the row you store won't be in the grid any more after the reset takes place. You will have to store some kind of key information about the row and then find that row again.
I used this in the past after refreshing...
grid.Rows.ScrollCardIntoView(grid.ActiveRow);
This takes a row that it scrolls into view you'll need to know where you are in the grid as your setting you active row to the first...