Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Synchronize Row Scrolling Between Grids When Only One Grid Is Visible
posted

I'm trying to keep the scroll position synchronized between two separate grids that exist on a tab control.  Thus only one of the grids is visible at a time.  Setting grid.ActiveRowScrollRegion.ScrollPosition for the *non-visible* grid simply does not work in this scenario (unless I'm missing something, which I certainly hope is the case!).

For example, I can easily keep the grids synchronized when they are both visible on the form at the same time, no issues here and it's one line of code to acheive this.

However, executing the exact code with only one grid visbile and the other sitting on a different, non-selected tab, setting the grid.ActiveRowScrollRegion.ScrollPosition doesn't take.  Stepping through the code shows that setting the value for the non-visible grid does not actually change its value, nor does it trigger  the row scroll event for that hidden grid.

Now I can understand this could be deliberate, in that performance wise it might not make a lot of sense to scroll a grid that is not seen, but the problem I'm encountering is finding the right entry point to actually do the scroll if it can't happen in real time.  For example, I can put the synchronization code behind a button, set the values equal to each other through that click event, and everything works fine (of course I don't want a button!).  

I could utilize the Paint event of the non-visible grid, and when that fires set the ScrollPosition.  However, then I have to implement some flags around to make sure the user can still manually scroll that grid without having its values reset to the values of the first (man, I hope that makes a even a little sense).

Putting this code in the VisibleChanged does not work, nor the SelectedTabChanged event in the tab control.

One last though, I have *ZERO* problems with column scrolling!  Setting the columns scroll position through code works perfectly whether or not both grids are visible, which is what leads me to question if this is expected behavior.

Any help would be greatly appreciated.