DataGrid / UI does not update consistently [Solved?]

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

DataGrid / UI does not update consistently [Solved?]

Post by mrcoollion » Thu Feb 17, 2022 10:45 am

Hi all,

I have the problem that a Datagrid does not update consistently during the running of a loop. Sometimes it does and sometimes I just see a bussy Cursor icon and it only updates after the loop has finished.
It seems to be depending on the number of updates and the time between the adding or changing of a line in the datagrid. When there are many updates in a short time I only see the busy cursor and the Datagrid only updates at the end of the loop, and when there are fewer updates it updates the Datagrid with every added or changed line. :shock:

Any idea's how to solve this without significantly slowing down the loop?

Kind regards,

Paul
Last edited by mrcoollion on Fri Feb 18, 2022 9:50 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: DataGrid does not update consistently

Post by dunbarx » Thu Feb 17, 2022 3:05 pm

How do you update? Do you:

Code: Select all

dispatch "ResetList" to group "yourDataGrid"
Craig

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: DataGrid does not update consistently

Post by mrcoollion » Thu Feb 17, 2022 5:12 pm

Hello Craig,

For adding a line I use:

Code: Select all

put  tNewPositionNbr into theLineNo
dispatch "AddData" to group "DG_SimulatedTrades" with theDataA, theLineNo

For updating a line I use:

Code: Select all

set the dgDataOfLine[tPositionNbr] of group "DG_SimulatedTrades" to pDataA
Regards,

Paul

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: DataGrid does not update consistently

Post by stam » Thu Feb 17, 2022 5:37 pm

Hi Paul,

I think Craig was giving you the answer rather than asking a question ;)

Personally if updating single lines, i'd call refreshLine after updating data or adding data:

Code: Select all

dispatch "RefreshLine" to group "DataGrid" with pLines
If you're doing a whole lot of updates, i'd use something like what Craig says instead of refreshing individual lines, but my preference is using refreshList to update the whole data grid instead:

Code: Select all

dispatch "RefreshList" to group "DataGrid"
In other words, after running your loop changing multiple records, call this at the end.


hope that helps,
Stam

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: DataGrid does not update consistently

Post by dunbarx » Thu Feb 17, 2022 7:30 pm

Stam reads me like a book.

I wish I did.

But, Stam, what is different between your post and mine?

Craig

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: DataGrid does not update consistently

Post by stam » Thu Feb 17, 2022 7:45 pm

dunbarx wrote:
Thu Feb 17, 2022 7:30 pm
But, Stam, what is different between your post and mine?
Not much in real terms i suspect. Some theoretical differences:

ResetList redraws the data grid data after having copied in fresh copies of any templates. Potentially a bit slower as it's reloading text, graphics, templates, layouts etc. Overkill for the OP's purpose as well...

RefreshList redraws the data displayed in the data grid. Potentially faster as it only refreshes the data.

RefreshLine redraws the data only for the specified line - potentially much fast if you're only changing the one line.

In real terms and especially for smaller data grids there is probably no noticeable difference between resetList and refreshList - but given that there is a speed penalty using the data grid anyway (compared to a table field for example) it makes me feel just a little bit better thinking i am eeking just a bit more speed out of the data grid ;)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: DataGrid does not update consistently

Post by dunbarx » Thu Feb 17, 2022 8:04 pm

Stam.

Ah, thanks. As I am fond of saying, "I use data grids, but do not understand them".

Craig

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: DataGrid does not update consistently [Solved?]

Post by mrcoollion » Fri Feb 18, 2022 9:49 am

Tried multiple solutions like

Code: Select all

 dispatch "RefreshList" to group "DG_SimulatedTrades"

Code: Select all

 set the backgroundColor of this card to the backgroundcolor of this card // Refresh screen
It seems that the UI lockes while running a repeat loop that goes through a few thousand iterations.
To prevent this I placed the following line at the beginning of the repeat loop and that worked.

Code: Select all

 wait 0 with messages // To stop UI from freezing
I thought this issue did not exist anymore (as of LC 7) :?: but it seems it still does.
It does not make the loop significantly slower so all is well now :)

Thanks for all the suggestions/help. Truly appreciate it.

Regards,

Paul

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: DataGrid / UI does not update consistently [Solved?]

Post by stam » Fri Feb 18, 2022 4:45 pm

Hi Paul, are you trying to refresh data in the middle of your loop?
If you are you probably shouldn’t… just run refreshList after the loop has completed and it should just refresh the data…

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: DataGrid / UI does not update consistently [Solved?]

Post by mrcoollion » Fri Feb 18, 2022 5:08 pm

stam wrote:
Fri Feb 18, 2022 4:45 pm
Hi Paul, are you trying to refresh data in the middle of your loop?
If you are you probably shouldn’t… just run refreshList after the loop has completed and it should just refresh the data…
You Are correct, I am refreshing the data during the loop. This is necessary to show the user what is happening during the loop. With the 'wait 0 with messages' command it works fine.

Thanks :D

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”