Page 1 of 2

Datagrid question

Posted: Wed Aug 19, 2020 3:40 pm
by marksmithhfx
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 4:13 pm
by Klaus
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 5:00 pm
by dunbarx
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 5:03 pm
by Klaus
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" 
 ...

Re: Datagrid question

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

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

Craig

Re: Datagrid question

Posted: Wed Aug 19, 2020 5:34 pm
by marksmithhfx
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.

Re: Datagrid question

Posted: Wed Aug 19, 2020 5:48 pm
by marksmithhfx
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.

Re: Datagrid question

Posted: Wed Aug 19, 2020 5:53 pm
by marksmithhfx
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?

Re: Datagrid question

Posted: Wed Aug 19, 2020 6:05 pm
by Klaus
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!

Re: Datagrid question

Posted: Wed Aug 19, 2020 7:49 pm
by dunbarx
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 10:04 pm
by marksmithhfx
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 10:29 pm
by marksmithhfx
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

Re: Datagrid question

Posted: Wed Aug 19, 2020 10:37 pm
by marksmithhfx
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 :|

Re: Datagrid question

Posted: Mon Aug 24, 2020 9:59 pm
by marksmithhfx
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

Re: Datagrid question

Posted: Tue Aug 25, 2020 4:57 am
by dunbarx
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