Datagrid first lesson

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
MarcVanCauwenberghe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 142
Joined: Thu Feb 21, 2013 8:47 am

Datagrid first lesson

Post by MarcVanCauwenberghe » Sat Jul 06, 2013 7:32 am

Hi,
I just tried the first lesson from the data grid lessons by Livecode.
Put a grid and a button on a card.
Then put the following in the mouse up

Code: Select all

 
   ## Create tab delimited data.
   ## Note that first line has name of columns.
   ## Providing names tells Data Grid how to map ## data to appropriate columns.
   put "state" & tab & "code" & cr & "ALABAMA" & tab & "AL" & cr & "ALASKA" & tab & "AK" into theText
   ## Let Data Grid know that first line has column names
   put true into firstLineContainsColumnNames
   set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to theText
When I try this out nothing happens?!?!?!
When I put a breakpoint on the last line I do see it go to there so it must be moving over the lines.

Any help?
Marc

MarcVanCauwenberghe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 142
Joined: Thu Feb 21, 2013 8:47 am

Re: Datagrid first lesson

Post by MarcVanCauwenberghe » Sat Jul 06, 2013 7:37 am

OK, wait a second. Just seen the same comment, I will have another try.

Till later,
Marc

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

Re: Datagrid first lesson

Post by dunbarx » Sat Jul 06, 2013 2:31 pm

Hi.

Be careful when using the "dgText" and the "dgData"

The first uses ordinary in-the-clear data, the second must be an array. This is true whether loading to or extracting from the DG.

Try changing the last line to:

set the dgText of group "DataGrid" to theText

Craig Newman

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

Re: Datagrid first lesson

Post by Klaus » Sat Jul 06, 2013 2:47 pm

HI Marc,

you need to create the two columns "state" and "code" first in the inspector for the datagrid!
The "firstLineContainsColumnNames" will only manage the correct order of your data, in case
the order of the data in the TAB text is NOT the order of columns in your datagrid!

Example: you have these columns in the datagrid
1. name
2. street
3. city

But your data come in columns with the wrong order like:
1. street
2. city
3. name

Then you can do this to get them correctly into your datagrid without needing to take care of re-ordering the data:
...
## the_wrongly_ordered_data conatain data in the wrong order as above
put "street" & TAB & "city" & TAB & "name" into tColumnOrder
set the dgtext[TRUE] of grp "DataGrid" to (tColumnOrder & CR & the_wrongly_ordered_data)
...
Et voila :-)


Best

Klaus

MarcVanCauwenberghe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 142
Joined: Thu Feb 21, 2013 8:47 am

Re: Datagrid first lesson

Post by MarcVanCauwenberghe » Sat Jul 06, 2013 3:44 pm

Thank you guys. It is as Klaus said. The columns should be defined beforehand. A bit counterintiutive for me but it does have its reasons.
This will be the more difficult part of learning Livecode coming from an other language.

Thanks again.

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

Re: Datagrid first lesson

Post by dunbarx » Sat Jul 06, 2013 6:12 pm

All:

Note that the column headers can be set under script control with something like:

set the dgColumnLabel["col 1"] of grp 1 to "yourNewLabel"

All aspects of a dataGrid can be manipulated by setting properties.

Craig Newman

MarcVanCauwenberghe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 142
Joined: Thu Feb 21, 2013 8:47 am

Re: Datagrid first lesson

Post by MarcVanCauwenberghe » Sat Jul 06, 2013 8:09 pm

That is one of the next things I was going to ask. Thank you Craig.

If I may just one more :

I am converting a grid like scheduler and in each cell I set the back-color and fore-color, the font and just one character. Could you tell me how to do this?
I am doing this cell by cell so I will have to use the FillIndata I think?
Attached is the windows version I would like to convert.
Attachments
grid.png
grid.png (5.13 KiB) Viewed 4730 times

Post Reply