Specify a Datagrid cell from another card

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Specify a Datagrid cell from another card

Post by mattrgs » Sat Feb 15, 2014 12:10 pm

Hi
I am trying to move the contents of a field into a datagrid which is on another card, but keep on getting errors. My current code for the line is:

Code: Select all

Put field "RecipeName" into group "RecipeGrid[1]["RecipeName"]",  card "card id 1009"
The error is:
"button "BtnSave": execution error at line 5 (Chunk: can't find background), char 27"
Can anyone please offer some help on this.
Thanks
Matthew

Klaus
Posts: 12204
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Specify a Datagrid cell from another card

Post by Klaus » Sat Feb 15, 2014 12:55 pm

Hi Mat,

a couple of basic things and hints:
1. give your cards (hopefully) meaningful names! :D
So you can address them with their names.
...
card "userinput"
...
If NOT, use the correct syntax:
...
## BAD and might throw an error:
## card "card id 1234"
## Correct:
card id 1234
...
Check these stacks to learn more about the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html

2. The correct "address" of objects is buld with OF:
...
put "some text" into fld "name of the target field here" OF cd "userinput" OF stack "another stack"
...
"of stack xyz" is only neccessary when the object you are addressing is not
in the same stack as the executing object/script.

3. Unfortunately "datagrids" are very special and complex beasts with their own syntax. :D
So you need to do something like this, because you cannot "update" a single colums directly:
...
## Put complete datagrid data into a variable
put the dgdata of group "RecipeGrid" of card id 1009 into tTempData

## Now update the content of this variable:
put field "RecipeName" into tTempData[1]["RecipeName"]

## And write the data back to the datagrid "en bloc":
set the dgdata of grp "RecipeGrid" of card id 1009 to tTempData
...
Go here:
http://lessons.runrev.com/m/datagrid
load the complete DataGrid manual PDF and learn it by heart! :)

But even if you do, you might need to read up again, when you are using datagrids the next time.
At least I need to, that's so *'%§$?? complex 8)

Hope that helps!


Best

Klaus

mattrgs
Posts: 37
Joined: Tue May 28, 2013 1:41 pm

Re: Specify a Datagrid cell from another card

Post by mattrgs » Sat Feb 15, 2014 8:31 pm

Thanks a lot that sorted out my problems, I think the main thing was that I couldn't directly refer to data while it was in the datagrid, but I now understand how to do that quite easily.
Thanks again
Matthew

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”