Page 1 of 1

DataGrid / UI does not update consistently [Solved?]

Posted: Thu Feb 17, 2022 10:45 am
by mrcoollion
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

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 3:05 pm
by dunbarx
How do you update? Do you:

Code: Select all

dispatch "ResetList" to group "yourDataGrid"
Craig

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 5:12 pm
by mrcoollion
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

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 5:37 pm
by stam
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

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 7:30 pm
by dunbarx
Stam reads me like a book.

I wish I did.

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

Craig

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 7:45 pm
by stam
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 ;)

Re: DataGrid does not update consistently

Posted: Thu Feb 17, 2022 8:04 pm
by dunbarx
Stam.

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

Craig

Re: DataGrid does not update consistently [Solved?]

Posted: Fri Feb 18, 2022 9:49 am
by mrcoollion
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

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

Posted: Fri Feb 18, 2022 4:45 pm
by stam
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…

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

Posted: Fri Feb 18, 2022 5:08 pm
by mrcoollion
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