update DataGrid without shifting view to origin

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

update DataGrid without shifting view to origin

Post by kwinkler » Wed Jan 26, 2011 10:08 pm

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.

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: update DataGrid without shifting view to origin

Post by Klaus » Wed Jan 26, 2011 10:15 pm

Hi kwinkler,

does it help when you "lock screen" before you update data and "unlock screen" after that?


Best

Klaus

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: update DataGrid without shifting view to origin

Post by kwinkler » Wed Jan 26, 2011 10:23 pm

Hi Klaus,

That was a great solution. Just what I needed.

Thanks,

Ken

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: update DataGrid without shifting view to origin

Post by kwinkler » Wed Jan 26, 2011 11:38 pm

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.

kwinkler
Posts: 61
Joined: Fri Nov 26, 2010 5:59 am
Location: Connecticut, USA

Re: update DataGrid without shifting view to origin

Post by kwinkler » Thu Jan 27, 2011 2:13 am

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”