We have a need to synchronize the scrolling of two grids
Grid1 A B C col1 col2 col3 .... col120
Grid2 D E col1 col2 col3 ..... col120
All colX's need to remain vertically aligned i.e col1 below col1, col2 under col2 etc. I am thinking I would have one scrollbar that would scroll both grids. That way colX's are always aligned.
- Should I control scrolling using a new ultrascrollbar? or have the two grids share one of their scrollbars
- How would can I make scroll position of the grid to set smoothly? Setting the ColScrollRegions.Position gives a jerky movement for the grid
Thanks!
Hello vrn,
As a possible approach to achieve this behavior you could hook onto the 'AfterColRegionScroll' event of the grids and pass the current scroll position of the current grid to the other grid's scroll position.
Please review my sample code:
private void ultraGrid1_AfterColRegionScroll(object sender, Infragistics.Win.UltraWinGrid.ColScrollRegionEventArgs e) { ultraGrid2.DisplayLayout.ColScrollRegions[0].Position = e.ColScrollRegion.Position; } private void ultraGrid2_AfterColRegionScroll(object sender, Infragistics.Win.UltraWinGrid.ColScrollRegionEventArgs e) { ultraGrid1.DisplayLayout.ColScrollRegions[0].Position = e.ColScrollRegion.Position; }
private void ultraGrid1_AfterColRegionScroll(object sender, Infragistics.Win.UltraWinGrid.ColScrollRegionEventArgs e)
{
ultraGrid2.DisplayLayout.ColScrollRegions[0].Position = e.ColScrollRegion.Position;
}
private void ultraGrid2_AfterColRegionScroll(object sender, Infragistics.Win.UltraWinGrid.ColScrollRegionEventArgs e)
ultraGrid1.DisplayLayout.ColScrollRegions[0].Position = e.ColScrollRegion.Position;
Feel free to let me know if something comes up.
Hi Boris,
I have implemeted sync horizontal scrolling as you described. I have only scrollbars visible in the "master grid". The master grid can be scrolled in both directions if needed. The "slave grid" should not show scrollbars, the amount of rows are fixed und should always be visible. If I scroll the master horizontylla, the slaves columns folows nicely setting the position of the master, BUT if the master shows his vertical scroll bar, the positions are not in sync anymore and the columns appears not at the same poistions.
My settings for scrolling are
e.Layout.ScrollStyle = ScrollStyle.Immediate; e.Layout.ScrollBounds = ScrollBounds.ScrollToFill;
Do I need also show a vertical scrollbar in the slave (just for keep in sync) or do I have another option? If not, how I can trigger when the master shows/hides his scrollbars?
Best regards
Markus
Hi,
If one grid has a vertical scrollbar and the other does not, then the scrollbar range of the two grids will be different. This will work fine, and I tried it out and it works, unless you scroll all the way to the right. In that case, when you scroll all the way to the right, there's no way to synchronize the scrolling because the grid without a scrollbar would have to scroll past the last column and end up showing empty space and it does not support that.
So the best solution is to have the scrollbar displayed on both grids.
Hi Mike,
the master grid shows scrollbars as needed (automatic). Showing vertical scrollbar in the slave grid is ok. I have found a post (http://es.infragistics.com/community/forums/t/12139.aspx) where you have placed a link to how determine if vertical scrollbar ist visible. Implementing this, I have (almost) a solution.
But when check it? At the moment I have placed this piece of code in the AfterColRegionScroll-event of the master grid. If the master grid hides the vertical scrollbar (users can change splitter positions of panels of the form), the slave grid still remains showing the vertical scrollbar and I have to manually scroll again to trigger the scroll event to hide the slave scrollbar.
I have not found an event that raises just when the master grid shows / hides his vertical scrollbar. Is there a way to trigger that? Sizes of some UI element changes or something like that?
Regards, Markus
Hi Markus,
There's no event specifically for when the scrollbar is shown or hidden. If you really want to hide/show the scrollbars dynamically, you would have to find a way to track every possible case where the scrollbars might be hidden or shown. So that would include any time a row is added or removed and whenever the height of the grid changes. It also depends on other factors, like if the horizontal scrollbar is visible (since this takes away from the available vertical space). And there may be other factors I'm not thinking of right now. it's tricky.
Another option would be to use an event that fires far more often than you need, like the Paint event. The grid will have to paint when the scrollbars are shown/hidden, but this event is going to fire a LOT and if you code is even a little but inefficient, it could cause a performance problem.
What I would do is explicitly turn on the vertical scrollbar in both grids all the time. That's the simplest way to handle it and the scrollbar will be disabled when it's not needed.
I have played around little bit and agree with your solution. The slave grid(s) (3 slave grids, right side, below and x-sum right-below) are some special summarizing of the masters grid content and can be showed / hide by the users.
At the point, where the slave grids are turned on I will show scrollbars anytime where needed to achieve sync-scrolling.
Thank you Mike.