How can I set the initial position of the scrollbar of a wingrid?
I mean that when the grid is shown, the scrollbar is on the right position I've set, not first the default position and then scroll to position I've set.
Every time I rebind the datasource and set the activerow, the scrollbar scrolls.
If anyone knows, please tell me.
Thanks in advance.
Thank you very much for you help.
I surrounded my code in a BeginUpdate/EndUpdate block and it worked.
So you want to set the ActiveRow but not scroll that row into view?
I'm not sure if you can sto pit from scrolling. You might try trapping the BeforeRowRegionScroll event and cancelling it. So you would have to set a flag, then set the ActiveRow, then re-set the flag. In your BeforeRowRegionScroll event, you would check the flag and if it's true, you would cancel the event. I'm not sure this will work, though. The event might not fire when you set the ActiveRow and even if it does, it might not fire synchonously.
If that doesn't work, what you can probably do is set the ActiveRow and then immediately set the ActiveRowScrollRegion.FirstRow to scroll to the first row in the grid. You could surround the code in a BeginUpdate/EndUpdate block so the grid doesn't paint.
Thanks for your reply. Maybe I didn't explain my problem properly.
My grid display 5 rows per screen and the active row is the 6th row. I rebind a new data source and then set the 6th row active.
When the grid is shown, the scrollbar scrolls to the next page. I don't want the user to see the proccess of scrolling.
Is there any way to let the grid show the second page when it is shown?
If you set the DataSource of the grid and then set the ActiveRow immediately afterward, I would think that the grid would paint the first time and already be scrolled to the proper position. If the grid is scrolling twice, then something must be forcing the grid to paint in between settings the data source and setting the ActiveRow.
Is your data source already loaded with data when you assign it to the grid? If you assign the DataSource first, and then populate it with data, this might cause the BindingManager to activate the first row in the grid and force a paint. In which case, you could get around it by either changing the order or setting SynchWithCurrencyManager to false.