I have a DataGrid that is sized so that only a small part of the data can be seen at one time. There are both vertical and horizontal scrollbars. Whenever I update the data by using 'set the dgData of group "myDataGrid......" ', the view of the DataGrid shifts to the top left, or origin, of the grid. Sometimes I want to watch a different part of the grid as I change model parameters, but this is not possible because the DataGrid insists on jumping to the origin of the grid.
Is there any way to prevent this behavior? I've tried using dgVScroll and dgHScroll to save the scrollbar positions before changing the data, and then resetting the scrollbar positions after changing the data, but this produces jumps between the two grid positions that is very distracting.
Any suggestions would be appreciated.
update DataGrid without shifting view to origin
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: update DataGrid without shifting view to origin
Hi kwinkler,
does it help when you "lock screen" before you update data and "unlock screen" after that?
Best
Klaus
does it help when you "lock screen" before you update data and "unlock screen" after that?
Best
Klaus
Re: update DataGrid without shifting view to origin
Hi Klaus,
That was a great solution. Just what I needed.
Thanks,
Ken
That was a great solution. Just what I needed.
Thanks,
Ken
Re: update DataGrid without shifting view to origin
It seems that lock/unlock screen do not work perfectly with a DataGrid. Upon unlocking the screen, the scrollbars appear where I want them to be. But the data values momentarily appear in the cell locations they would be in if the scrollbars had moved to the origin, and then appear in the correct locations. The DataGrid values flicker. So the screen does not fully update between locking and unlocking.
But it is usable, and a big improvement over not using lock/unlock screen.
But it is usable, and a big improvement over not using lock/unlock screen.
Re: update DataGrid without shifting view to origin
and the solution is.......
If the code is written like this, the DataGrid will sometimes flicker-
lock screen
set the dgData of group "myDataGrid" of stack "dataStack" to allDataArray -- load Data Grid
set the dgVScroll of group "myDataGrid" of stack "dataStack" to dgVScrollParm -- restore scrollbars to saved
set the dgHScroll of group "myDataGrid" of stack "dataStack" to dgHScrollParm
unlock screen
But if you reverse the order of setting dgVScroll and dgHScroll, there is no flicker. I have no idea why this works.
lock screen
set the dgData of group "myDataGrid" of stack "dataStack" to allDataArray -- load Data Grid
set the dgHScroll of group "myDataGrid" of stack "dataStack" to dgHScrollParm
set the dgVScroll of group "myDataGrid" of stack "dataStack" to dgVScrollParm -- restore scrollbars to saved
unlock screen
If the code is written like this, the DataGrid will sometimes flicker-
lock screen
set the dgData of group "myDataGrid" of stack "dataStack" to allDataArray -- load Data Grid
set the dgVScroll of group "myDataGrid" of stack "dataStack" to dgVScrollParm -- restore scrollbars to saved
set the dgHScroll of group "myDataGrid" of stack "dataStack" to dgHScrollParm
unlock screen
But if you reverse the order of setting dgVScroll and dgHScroll, there is no flicker. I have no idea why this works.
lock screen
set the dgData of group "myDataGrid" of stack "dataStack" to allDataArray -- load Data Grid
set the dgHScroll of group "myDataGrid" of stack "dataStack" to dgHScrollParm
set the dgVScroll of group "myDataGrid" of stack "dataStack" to dgVScrollParm -- restore scrollbars to saved
unlock screen