Data Grid From - Row Behaviour - Set control custom prop.

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
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Data Grid From - Row Behaviour - Set control custom prop.

Post by palanolho » Wed Sep 18, 2013 8:22 pm

Greetings everyone.

I'm starting to play with Data Grids and I'm having some trouble with a situation.

I created a data grid and in the template I defined:
- a button
- a lable (ID)
- a lable (Name)

What I need is to pass the ID to a new stack that will open when I click on the button on the row, so, I thought that the best way to do it was to add the ID as a custom property of the button on the template.

this is the datagrid row behaviour

Code: Select all

on FillInData pDataArray
     set the tknId of button "tokenOptions" to pDataArray["tokenId"] -- this is the button
     set the text of field "tokenId" of me to pDataArray["tokenId"]
     set the text of field "tokenName" of me to pDataArray["tokenName"]
end FillInData
this is the code on the button on the row

Code: Select all

on mouseUp
     put the tknId of me into tID
     answer "Will show options dialog here!!! (tokenID = " & tID & ")"
end mouseUp

Them I have a button on my application to add a new row

Code: Select all

on mouseUp
     put "1000" into theDataA["tokenId"]
     put "New Token" into theDataA["tokenName"]
     
     put 1 into theLineNo
     
     dispatch "AddData" to group "tokensDataGrid" with theDataA, theLineNo
     put the result into theNewIndex -- integer if successful, error string otherwise
     
end mouseUp
When I add the first row, everything is OK. The labels show the ID and the Name and when I click on the button is answers the id "1000" (OK)

but when I add more rows, the name and id on the label is OK but when I click on the button of the new lines, the answer is blank ""

Anyone has any idea why this is happening? is there any better way to do this? (get the ID of the item on the row when clicking in the button of the row)

Many thanks in advance for any help you can provide.

- Miguel

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by palanolho » Thu Sep 19, 2013 8:42 pm

I'm trying to go around this problem but with no success.

I tried to change the way I was setting the custom property of my button but not, it gives me a "Chunk: no such object" error

I'm setting the custom property like this

Code: Select all

     put the ID of button "tokenOptions" of me into tmpID

     --set the tknId of button tmpID to pDataArray["tokenId"]
     put pDataArray["tokenId"] into tknId of button tmpID
anyone has any idea why this is not working?

many thanks

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

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by Klaus » Thu Sep 19, 2013 8:50 pm

Hola Miguel,

there is a OF ME missing in your FillInData handler:

Code: Select all

on FillInData pDataArray
     set the tknId of button "tokenOptions" OF ME to pDataArray["tokenId"] -- this is the button
     set the text of field "tokenId" of me to pDataArray["tokenId"]
     set the text of field "tokenName" of me to pDataArray["tokenName"]
end FillInData

Code: Select all

put pDataArray["tokenId"] into tknId of button tmpID
Wrong syntax for setting a custom property, you need to:

Code: Select all

set THE custom_prop_name OF XYZ to zxy
You had it right in the line before :D

Best

Klaus

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by Simon » Thu Sep 19, 2013 8:56 pm

Hi Miguel,
Just a thought on your first posting (which seems to be good).
Why not try:

Code: Select all

on mouseUp
    -- put the tknId of me into tID --remove this line
     answer "Will show options dialog here!!! (tokenID = " & field "tokenId" & ")"
end mouseUp
might need "field "tokenId" of me"
They should be the same right? Saves you from dealing with a custom property of the button.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by palanolho » Thu Sep 19, 2013 9:19 pm

Because the information I'm displaying at the moment is just to play around.

I will change everything later but I know that when I click on the button, I want to open a new stack and display some information based on the ID of the data displayed on the row.

That's why :)

Its kinda like "lets see how this work... Cool, its works. Now lets do it with the correct data..."

cheers
- Miguel

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

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by Klaus » Thu Sep 19, 2013 9:38 pm

Hola Miguel,

sure :D

But please try my suggestion with OF ME!

Explanation 8)
If you leave out the "descriptor" -> OF ME, then Livecode will seek
the FIRST button (lowest layer) with that name and will ONLY
address that first button with that name.

That means that only the first button with that name in your datagrid ,
which may have N buttons with that name in separate groups, will ever
get its custom property set when all ROWS are filled.

The custom property will always be overwritten but with different values.
Know what I mean?


Best

Klaus

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by palanolho » Thu Sep 19, 2013 9:49 pm

I tried the OF ME but didn't work either :(

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

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by Klaus » Thu Sep 19, 2013 10:03 pm

Oh, hmmm? Sorry, no idea in the moment.

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by palanolho » Fri Sep 20, 2013 8:03 pm

Situation Resolved :)

it was a minor bug I introduced on the alert when trying to figure out what was the problem :roll:

the OF ME worked just fine, thanks !!!

Cheers,
- Miguel

abhinav7979
Posts: 5
Joined: Mon Jan 04, 2016 1:10 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by abhinav7979 » Mon Jan 04, 2016 1:42 pm

Hello,

I'm having a similar problem . I have created a row template for data grid in "cust_assignment" card with
  • Name
  • Time
  • Button
This is my button Behavior Script:

Code: Select all

global dgArrayGrid
global ca_id_cp

on FillInData pDataArray
 set the ca_id_cp of button "btn_select_cust"  of me to pDataArray["ca_id"] --custom property
 set the cust_name_cp of button "btn_select_cust" of me to pDataArray["cust_id"]--custom property
 set the text of field "cust_name" of me to pDataArray["cust_name"]
 set the text of field "lbl_time_ca" of me to pDataArray["pickup_time"]
end FillInData
Now I want to pass the row details to another card on the button click. I have defined two custom properties for button : ca_id_cp,cust_id_cp
This is the code of my row template button:

Code: Select all

on mouseUp
 global tID
 
 put the ca_id_cp of me into tID
 answer tID
 send (tID && tID) to the  card "customer_landpage"
 go to card "customer_landpage"
end mouseUp
I want to pass these two values of the row when clicked the button, to the next card "cust_landpage"

Please help me out in the right direction. I tried several things. I'm not sure how to proceed.

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

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by Klaus » Mon Jan 04, 2016 2:09 pm

Hi abhinav7979,

1. welcome to the forum! :D

2. You cannot "send" (only) two variables to a card or whereever, only handlers!
And why twice the same variable? Luxury! :D

You already declared tID as a global variable, well, that's all you need,
since global variables are available to every script of every object/card/stack!

Now you need to "pick up" that variable in the preopen- or opencard script of card "customer_landpage"
and do whatever you need to do with that variable. Something like this in the script of card "customer_landpage":

Code: Select all

global tID

on opencard
  ## do something with this variable here...
end opencard
Hint: Do not use THE when addressing objects or card or stacks:

Code: Select all

...
## send "my_handler to the  card "customer_landpage"
send "my_handler to card "customer_landpage"
...
Best

Klaus

abhinav7979
Posts: 5
Joined: Mon Jan 04, 2016 1:10 pm

Re: Data Grid From - Row Behaviour - Set control custom prop

Post by abhinav7979 » Wed Jan 06, 2016 7:25 am

Thank you @Klaus

I worked it out. Figured I was not thinking straight while writing that :) But your reply helped me in the right direction.

I had included controls on row template itself which display the values i need to pass. I saved the global array of row data of all controls on row click event. It's working good. :)

Wishes

-Abhinav

Post Reply