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.
There are quite a number of factors here that are unknown. Can you post a small sample project demonstrating this issue? If so, I would be happy to take a look and see if I can make it work, or determine if this is a bug.
Hi Mike,
Thanks for offering to take a look. I've uploaded a zip archive containing a very simple sample solution which demonstrates this issue. As is, with the grids on separate tabs, you will see that attempting to sync the rows will not work. However, if you drag the second grid out of the tab control to be visible on the form, it works fine. Stepping through the code, with the grids on the tabs, it becomes plain to see that setting the ScrollPosition property is just not holding.
I've only included a few events for the form just to show you the issue.
Thanks again.