Unable to update datagrid with new data

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
charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Unable to update datagrid with new data

Post by charms » Sat May 31, 2014 1:36 pm

Followed this tutorial which explains how to add checkboxes to datagrid rows instead of using selection (required because of mobile devices):
http://lessons.runrev.com/m/datagrid/l/ ... -data-grid

Nice, but it does not explain how to implement a handler that will execute once a checkbox was checked or unchecked.

My solution in the behaviour onMouseUp script: dispatch "dgSelectedIndexChanged" with the dgindex of me

Code: Select all

on mouseUp pMouseBtnNum
    if pMouseBtnNum is 1 then
        ## did they click on the checkbox?
        if the short name of the target is "Check" then
            ## Update internal value in data grid
            SetDataOfLine the dgLine of me, "checked", the hilite of the target
			dispatch "dgSelectedIndexChanged" with the dgIndex of me -- added this message for which i implement the command in the card script
        end if
    end if
end mouseUp
In the card script:

Code: Select all

on dgSelectedIndexChanged pIndex
   local theDataA
   
   put "Line 3" into theDataA[1]["label"]
   put "true" into theDataA[1]["checked"]
       
   put "Line 4" into theDataA[2]["label"]
   put "false" into theDataA[2]["checked"]
       
   answer "before dgData update"
   
   set the dgData of group "DataGrid 1" to theDataA
   answer "after dgData update"
end dgSelectedIndexChanged
answer "after dgDate update" is never executed. set the dgDate of group "DataGrid 1" to theData fails completely.

Why is it not possible to update the dgData this way? I use the normal message path.

How can I get this right? I need to know when the status is changing so that I can act up on each change.

AFTER SOME DATAGRID SCRIPT DEBUGGING

I found out that the error is happening in private command _list.DeleteControls after the extra cleanup comment in the second repeat which deletes a control 1 in dgList.

Code: Select all

 ## Any extra cleanup
   repeat until there is not a (group 1 of group "dgList" of me)
      delete group 1 of group "dgList" of me
   end repeat
   --   answer "_list.DeleteControls after extra cleanup"
   --   repeat until there is not a control 1 of group "dgList" of me
   --      answer the short id of control 1 of group "dgList" of me
   --      delete control 1 of group "dgList" of me
   --   end repeat
After I've commented out this section it worked. So for me this is a datagrid bug which I opened a bug report already.

After some more debugging I discovered that dgList is the list that contains all rows. The repeat loop loops through all the row templates and removes each one. I guess before the new data can be populated.

I assume at the moment that the onMouseUp command within the row behaviour is still executing while the code to cleanup the dgList is running and therefore the data can't be written or is written but just deleted again, because the repeat will continue while it finds rows.

So it could be that this is not a bug. But then I still wonder how I can send a message that indicates that something has changed and action is required.

Reminds me about the Monkey Island Adventure Game: Get the meat, and the pot. Chase the bird away by rocking the plank.When it flies away, get the fish. Go to the circus, put the pot on head, get in canon.... It's about the same complex logic. :mrgreen:

Kind regards,
Chris
Attachments
datagrid_checkbox 1.livecode.zip
(6.08 KiB) Downloaded 217 times

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: Unable to update datagrid with new data

Post by charms » Tue Jun 03, 2014 9:13 pm

I think my friend just gave me the solution. I think the functionality above is only possible by using two datagrids and just hide and show them vice versa when the data is changing.

After failing with the datagrid I've created my own small datagrid with objects inside a group. I have used the similar methods. Once I clicked on to the button to renew the data it failed to delete the button i was clicking on. So filling the group with new data was also not possible. I think in datagrid under the hood the same happens. The problem with datagrid is just that it doesn't throw any errors out of some reason. So debugging is extremely hard.

I'll try to do it with two datagrids.

Kind regards,
Chris

charms
Posts: 122
Joined: Mon Feb 10, 2014 6:21 pm
Contact:

Re: Unable to update datagrid with new data

Post by charms » Tue Jun 03, 2014 10:12 pm

Hrrrrmmmmm....... I must admit..... Using two datagrids works just fine....

It's different from what I'm used to with other languages.... and I don't know if there are performance impacts because of the 16000 lines.... but at least it works

Please note that copying the datagrid could have side effects. I just created both by hand.

Kind regards,
Chris
Attachments
datagrid_checkbox 1.livecode 2.zip
(11.93 KiB) Downloaded 205 times

Post Reply