Define Datagrid Form Columns

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

Post Reply
Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 55
Joined: Sat Oct 15, 2011 9:43 am

Define Datagrid Form Columns

Post by Batninja » Tue Nov 08, 2016 6:49 pm

Hi, hope someone can help me on this please.

I can't see how the columns used in a Datagrid Form are defined. In the tutorial "Creating a list of people" the datagrid behaviour script FillInData uses values from columns pDataArray["LastName"], pDataArray["FirstName"], pDataArray["Title"] and pDataArray["Image URL"], which works fine when I follow the exercise.
e.g.
set the text of field "Name" of me to pDataArray["LastName"] & comma & space & pDataArray["FirstName"]
set the text of field "Title" of me to pDataArray["Title"]
set the filename of image "image" of me to pDataArray["Image URL"]

But if I create a new Datagrid Form the columns seem to be setup automatically as "label 1", "label 2", "label 3"which I found just by guessing!

i.e. this code in a new Datagrid Form behaviour script works fine:
set the text of field "Width" of me to pDataArray["label 1"]
set the text of field "Height" of me to pDataArray["label 2"]
set the text of field "Name" of me to pDataArray["label 3"]

But where does label 1 etc come from? In a data grid table then they are setup in the properties but when you choose a Datagrid Form the columns tab disappears. I haven't setup label 2 or label 3, are they the defaults in the pDataArray variable?

Any help or suggestions gratefully received on to how to specify the column headers in a Datagrid Form?

Roger

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

Re: Define Datagrid Form Columns

Post by Klaus » Tue Nov 08, 2016 7:12 pm

Hi Roger,

how are you creating the ARRAY used to fill in the data?
They must be created somewhere and at some pont and that's the time where the names of the keys are defined! :D


Best

Klaus

Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 55
Joined: Sat Oct 15, 2011 9:43 am

Re: Define Datagrid Form Columns

Post by Batninja » Tue Nov 08, 2016 9:48 pm

Thanks Klaus

I started to think it must be something to do with the pDataArray array variable. But I did not create it, just added a Datagrid to my card and set it as a form.

Presumerably the array is set by default. Does this mean I just need to modify the pDataArray?

THanks for your assistance so far!

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

Re: Define Datagrid Form Columns

Post by Klaus » Wed Nov 09, 2016 12:52 pm

OK, but how do you get whatever data into your datagrid?

There is nothing that could happen automatically this way,
there must be s script involved somehow at some point! 8)

Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 55
Joined: Sat Oct 15, 2011 9:43 am

Re: Define Datagrid Form Columns

Post by Batninja » Wed Nov 09, 2016 1:14 pm

Ok I think I have solved it!

If you:

1. Add a datagrid control(by default it is a table)
2. Change to a Form
3. Edit Behaviour script - then the columns headers are named label 1, label 2, label 3 - etc.

However if you:
1. Add a datagrid control (by default it is a table)
2. Configure columns in the table (e.g. naming them Width, Height and Name)
3. Change to a Form
Then the behaviour script and pDataArray uses the columns names assigned in the original datagrid table

i.e. this code works in the behavior script:

Code: Select all

on FillInData pDataArray
   set the text of field "Height" of me to pDataArray["Height"]
   set the text of field "Name" of me to pDataArray["Name"]
end FillInData
Thanks for your input, just writing it down and getting feedback helps to make it clearer.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Define Datagrid Form Columns

Post by SparkOut » Thu Nov 10, 2016 11:44 pm

Why a day? Clearly a spammer, even without today's evidence

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

Re: Define Datagrid Form Columns

Post by Klaus » Fri Nov 11, 2016 10:49 am

I am a generous guy, you know, but whom ecxactly are you talking about? :D

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Define Datagrid Form Columns

Post by SparkOut » Fri Nov 11, 2016 7:22 pm

Him, over there behind that pile of distraction

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

Re: Define Datagrid Form Columns

Post by Klaus » Fri Nov 11, 2016 7:30 pm

Ah, I see!
Not! :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”