text of header in dataGrid

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

Post Reply
operoutka
Posts: 7
Joined: Tue Apr 04, 2006 6:50 am

text of header in dataGrid

Post by operoutka » Thu Oct 20, 2016 7:46 pm

Hi,
I don't know how to put the text into header dataGrid table. I tried code:

set the dgText [true] of group "myDGname" to myTextHeader

This line doesn' make anything but the line code:

set the dgText of group "myDGname" to myTextHeader

This line code put text from myTextHeader into data grid tablet "myDGname".

I tried:
true as "true"
true into variable and variable into []
I don' know what I do wrong. Can enybody help me?

Oldrich

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

Re: text of header in dataGrid

Post by Klaus » Fri Oct 21, 2016 1:32 pm

Hi Oldrich,

1. welcome to the forum! :D

2. Why is everyone starting with the most complex object, the DATAGRID, in Livecode?
This is a rhetorical question! 8)

The parameter to -> dgtext[TRUE/FALSE] does NOT change the header labels nor does it add or remove columns! See below for more info...*
To do so you need to:
...
set the dgprop["column labels"] of grp "your datagrid here..." to CR_delimited_list_of_header_names
...

From the datagrid docs:
...
dgText
- get the dgText [pIncludeColumnNames]
- set the dgText [pFirstLineContainsHeaders] of group "DataGrid" to pText
- The data grid works with arrays behind the scenes but in the interest of making life easier for some folks there is a dgText property. The dgText property always reflects the same value as the dgData but in tab delimited form.

pText is assumed to be a collection of data where each row is delimited by the return character and each item is delimited by a tab. You can map each item of each line in pText to a particular key in an array (and thus a table column) by passing in true for pFirstLineContainsHeaders. If true then the data grid will extract the first line of pText and use the values for the internal key/column names. The default value for pFirstLineContainsHeaders is false.
If you set the dgText of a data grid table then all data will be imported and assigned to the appropriate column depending on the value of pFirstLineContainsHeaders. Normally you should set this property to true and provide the header that maps each item of each line to a specific column. Note that if pFirstLineContainsHeaders is true then the columns must already exist in your data grid table in order to be displayed.
If pFirstLineContainsHeaders is false then the columns property of the data grid is used for mapping. For example, the first item of a line of pText would be assigned to the column that appears on the first line in the columns property of the data grid. If line 1 of pText contains more items than there are columns in the table then new columns are added. Any new columns are named "Col 1", "Col 2", etc.
...
Do yourself a favour and download the docs as PDF here: http://lessons.livecode.com/m/datagrid, TINY link under TOPICS on the left,
read it up a couple of times, work throught the examples and read it up again a couple of times when you need to use it in LC, like I do :D


Best

Klaus

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

Re: text of header in dataGrid

Post by Klaus » Fri Oct 21, 2016 1:34 pm

Will move this thread to the "Beginner" forum, since "DataGrid Helper" is in fact a third-paty add-on to Livecode:
http://www.aslugontheroad.com/ourproducts

So the forum title might be a bit misleading :D

MaxV
Posts: 1498
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: text of header in dataGrid

Post by MaxV » Wed Oct 26, 2016 2:20 pm

dgtext can't set the column labels.
If you use dgText[true] , you declare that the first line is the column name to use to assign the data.
So if your datagrid has 3 columns: col1, col2 and col3
You can legally use:

########CODE#######
on mouseUp
put "col3" & TAB & "col2" & return & "a3" & TAB & "a2" into temp
set the dgtext[true] of group 1 to temp
end mouseUp
#####END OF CODE#####

Because the first line is used just to map data. As explained here: http://livecode.wikia.com/wiki/Datagrid ... umn_labels you have to use the dgProp["column labels"], for example:
########CODE#######
set the dgProp["column labels"] of group "myTable" to ("Column 1" & return & "My Perfect Column 2")
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5380
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: text of header in dataGrid

Post by dunbarx » Wed Oct 26, 2016 2:29 pm

I have a long standing stupid joke.

"I use dataGrids, but do not understand them.

@MaxV. I do not understand your handler. Only this:

Code: Select all

on mouseUp
put "col3" & TAB & "col2" & return & "a3" & TAB & "a2" into temp
set the dgtext of group 1 to temp
end mouseUp
sets the text of the DG, and the "col1..." stuff appears in the first line. If I use your "dgtext[true] construction, nothing happens at all.

Craig Newman

MaxV
Posts: 1498
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: text of header in dataGrid

Post by MaxV » Thu Oct 27, 2016 10:50 am

dunbarx wrote: @MaxV. I do not understand your handler. Only this:

Code: Select all

on mouseUp
put "col3" & TAB & "col2" & return & "a3" & TAB & "a2" into temp
set the dgtext of group 1 to temp
end mouseUp
sets the text of the DG, and the "col1..." stuff appears in the first line. If I use your "dgtext[true] construction, nothing happens at all.

Craig Newman
Note that set dgText[true] acts differently of put dgText[true].
This code for example:

Code: Select all

put the dgText[true] of group "DataGrid" 
returns:

Code: Select all

Col 1	Col 2	Col 3
a1	b1	c1
a2	b2	c2
but I can set the same values putting this into temp:

Code: Select all

Col 3	Col 1	Col 2
c1	a1	b1
c2	a2	b2
using this code:

Code: Select all

set the dgText[true] of group "DataGrid" to temp
because the TAB delimited item of the first line is used to map the column, and put the values of that temp column in the respective datagrid column with that name.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”