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
140
How can I synchronize the scroll position of grids after a resize?
posted

I'm trying to keep the vertical scroll position of two similar grids in sync.  To do this, I am handling the AfterRowRegionScroll event of both grids like so:

            ultraGrid1.AfterRowRegionScroll += (s, e) =>
            {
                ultraGrid2.EventManager.SetEnabled(GridEventIds.AfterRowRegionScroll, false);
                ultraGrid2.DisplayLayout.RowScrollRegions[0].ScrollPosition = e.RowScrollRegion.ScrollPosition;
                ultraGrid2.EventManager.SetEnabled(GridEventIds.AfterRowRegionScroll, true);
            };

This works well for synchronizing the scrolling.  Where I am having a problem, though, is when the grids resize.  I have both grids anchored top/bottom to the form.  If the grids are scrolled to the bottom and then are resized larger, I would assume they both would stay scrolled to the bottom, with just more rows showing (I have the grids' ScrollBounds set to 'ScrollToFill').  Instead one of the grids scrolls to the bottom fine, while the other scrolls past the bottom and leaves half the grid with empty space.

What it seems like is happening, is that when the grids resize, they fire off their AfterRowRegionScroll position with their old scroll position, rather than the new one.  The causes the second grid that resizes, to resize the first grid with its old scroll position.  This scrolls the first grid too far down and leaves the grid half empty.

The grids resize correctly without the synchronization code in place, but I can't find a good place to disable/enable the events.  Any ideas on how to keep the grids synced when resizing them?

I included a small sample project to illustrate the problem.

ScrollSyncOnResize.zip