Page 1 of 1
Datagrid first lesson
Posted: Sat Jul 06, 2013 7:32 am
by MarcVanCauwenberghe
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
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 7:37 am
by MarcVanCauwenberghe
OK, wait a second. Just seen the same comment, I will have another try.
Till later,
Marc
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 2:31 pm
by dunbarx
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
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 2:47 pm
by Klaus
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
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 3:44 pm
by MarcVanCauwenberghe
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.
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 6:12 pm
by dunbarx
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
Re: Datagrid first lesson
Posted: Sat Jul 06, 2013 8:09 pm
by MarcVanCauwenberghe
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.