Datagrid question

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

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 3:40 pm

Hi, I am having trouble sending a message to a DG handler I created (row template behavior script):

Code: Select all

on AddNewRow
   answer "We are here"
end AddNewRow
I'm calling this from a button on a card:

Code: Select all

on mouseUp pButtonNumber
   dispatch "AddNewRow" to group "DataGrid 1" 
   if not(it = "Handled") then
      ## handle the error
      put "Unable to Add New Row: (" & it & ")" into tErrMsg
      answer error tErrMsg as sheet
   end if
end mouseUp
The answer dialog never appears and the "it" responses in the button is "unhandled". Any suggestions?

Thanks
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid question

Post by Klaus » Wed Aug 19, 2020 4:13 pm

Hi Mark,

I'm afraid the behavior of the row template is NOT in the message path so your dispatch will go into datanirvana as you have experienced. The behavior of the datagrid and the datagrids script are in the message path however.

So maybe put the "addnewrow" handler into the script of the datagrid group itself?


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid question

Post by dunbarx » Wed Aug 19, 2020 5:00 pm

Hi.

The script of the DG is the script of the group that, er, is the DG. Can you dispatch your message to the group script?

Code: Select all

 dispatch "AddNewRow" to group "yourDG" 
Craig

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid question

Post by Klaus » Wed Aug 19, 2020 5:03 pm

Well, that's what he did first:
marksmithhfx wrote:
Wed Aug 19, 2020 3:40 pm
...
I'm calling this from a button on a card:

Code: Select all

on mouseUp pButtonNumber
   dispatch "AddNewRow" to group "DataGrid 1" 
 ...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid question

Post by dunbarx » Wed Aug 19, 2020 5:26 pm

I know, What I guess I meant was:

Mark, do you have a handler "addNewRow" in the group script?

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 5:34 pm

dunbarx wrote:
Wed Aug 19, 2020 5:26 pm
I know, What I guess I meant was:

Mark, do you have a handler "addNewRow" in the group script?

Craig
Craig, if I understand your question, yes. The AddNewRow script is in the same script as Fillindata and Layoutcontrol. (ie. select dg, open properties, click "Edit script" just above "Row template" button). I'm trying to call it from a button outside the group.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 5:48 pm

Hi Mark,
So maybe put the "addnewrow" handler into the script of the datagrid group itself?
Klaus
So write now I am going in to the datagrid, selecting the Data Grid pane from the properties menu and clicking on Edit Script. That is where the AddNewRow script is, and also the Layoutcontrol and Fillindata handlers. I've also added on CloseField and CloseStack handlers in this script. Close field works very well. Have not tested CloseStack yet.

There is a lesson showing how to add a new row that I have more or less copied, "How Do I Add A Row Of Data To An Existing Data Grid?" But instead of calling AddData like Trevor did, I am trying to call my own handler. For reasons, I am trying to sync events with an SQLite database. I've made good progress to date but then strangely got hung up trying to get this new row thing working. I think it's because I am defining my own handler where all previous handlers have been built ins (like CloseField).

Puzzling.
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 5:53 pm

Klaus wrote:
Wed Aug 19, 2020 4:13 pm
I'm afraid the behavior of the row template is NOT in the message path so your dispatch will go into datanirvana as you have experienced. The behavior of the datagrid and the datagrids script are in the message path however.
Is the template associated with the DG not the one on the Data Grid pain in properties labeled "Edit Script". It there another one? It says at the top of the script....
-- This script defines the behavior of your data grid's custom template. This behavior
-- only applies to 'forms' and not 'tables'.
I am using a form dg. So maybe this is just the behavior for the grid and not the DG itself?
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid question

Post by Klaus » Wed Aug 19, 2020 6:05 pm

marksmithhfx wrote:
Wed Aug 19, 2020 5:53 pm
...on the Data Grid pain...
Freudian slip? But very true! :-)
marksmithhfx wrote:
Wed Aug 19, 2020 5:53 pm
Is the template associated with the DG not the one on the Data Grid pain in properties labeled "Edit Script". It there another one?
The GROUPs script itself!

As I wrote the row beahvior is not in the message path of the datagrid.
Put the your script into the GROUPs script, that will work fine.
marksmithhfx wrote:
Wed Aug 19, 2020 5:53 pm
It says at the top of the script...I am using a form dg. So maybe this is just the behavior for the grid and not the DG itself?
As it reads, this is just the behavior of the ROW. FORM or TABLE does not matter.
The DGs actual behavior is a > 3000 lines LC library!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid question

Post by dunbarx » Wed Aug 19, 2020 7:49 pm

Klaus and I have both mentioned that the handler(s) have to be in the GROUP script in order for them to respond to messages.

Imagine that you had a card with a button on it, and that button had a handler in its script. You could not send a message to the card and expect the button handler to "see" it. You would have to send a message explicitly to the button.

Similarly, a DG is a whole lot of controls and behaviors, all assembled into an overarching group. But only the group will "see" messages unless you explicitly send that message to a control within the group.

For example, the first field in the first column of a DG is named "col 1 0001". You could set the script of that field, and send a message directly to it. But this is rarely done, since the whole point of a DG is not to need such functionality.

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 10:04 pm

dunbarx wrote:
Wed Aug 19, 2020 7:49 pm
Similarly, a DG is a whole lot of controls and behaviors, all assembled into an overarching group. But only the group will "see" messages unless you explicitly send that message to a control within the group.
Craig
Thanks guys, for something like the DG it can get complicated quickly. Anyway, after a long coffee break and a bite to eat I came back, decided to open up the script for the DG (right click on the DG, select edit script), plonked the code in there and it worked. So, the button was able to "reach" the datagrid to execute some code, but could not reach the form behaviour script. It would be nice to have a visual I guess, so we could see where are all the objects are and what is in the path of what. I never did comprehend that which I suspect is a barrier to my truly "getting" livecode. Nevertheless this is working, sort of :) Once I got the new rows added and I am doing this all manually, probably breaking all the DG rules, I lost the ability to re-order rows. You can pick them up and drag them around ok, but they don't really shuffle everything else around them like they used to. I was just reading up on AddData and I suspect that is the direction I will need to go.
pDataArray is an array of custom data to add to the data grid and pLine is the line number where it should be added. All data appearing at or after pLine will be shifted down 1. You will not overwrite any data. If pLine is empty then the data will be added to the end of the existing data.

If the data is successfully added then the index of the data will be returned in the result, otherwise an error is returned.
I'll let you know how it goes.
Cheers,
M
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 10:29 pm

dunbarx wrote:
Wed Aug 19, 2020 7:49 pm
Imagine that you had a card with a button on it, and that button had a handler in its script. You could not send a message to the card and expect the button handler to "see" it. You would have to send a message explicitly to the button.

Similarly, a DG is a whole lot of controls and behaviors, all assembled into an overarching group. But only the group will "see" messages unless you explicitly send that message to a control within the group.
Ok, I see what you are saying. Never thought of it that way. Thanks

M
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Wed Aug 19, 2020 10:37 pm

You know its really too bad the animations, swipes and reordering don't work anymore because everything else works perfectly. If I add a new row, it adds one to the DB, if I edit a row, the edits are recorded in the DB. The DB and DG are perfectly in sync. Only now, all of the fancy new DG2 features Michael (I think) added aren't working. I broke it. Sigh. Oh well, try again :|
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Datagrid question

Post by marksmithhfx » Mon Aug 24, 2020 9:59 pm

marksmithhfx wrote:
Wed Aug 19, 2020 10:37 pm
You know its really too bad the animations, swipes and reordering don't work anymore because everything else works perfectly. If I add a new row, it adds one to the DB, if I edit a row, the edits are recorded in the DB. The DB and DG are perfectly in sync. Only now, all of the fancy new DG2 features Michael (I think) added aren't working. I broke it. Sigh. Oh well, try again :|
Still working on this, but making good progress. In the interests of correct form, here is a question; where is the best place to set the dgdata of the datagrid on launch; openCard or preOpenCard? Or does it matter?

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid question

Post by dunbarx » Tue Aug 25, 2020 4:57 am

where is the best place to set the dgdata of the datagrid on launch; openCard or preOpenCard? Or does it matter?
Likely does not matter. To be completely safe, use preOpenCard.

Craig

Post Reply