Selecting a Datagrid column using a variable

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
DukeUK
Posts: 23
Joined: Sun Dec 06, 2009 5:55 pm

Selecting a Datagrid column using a variable

Post by DukeUK » Fri Nov 25, 2011 12:14 pm

I just can't get this to work.

I'm trying to get the contents of a datagrid cell from a column, where I use a variable to define the actual column.

This is the problem I'm having:

put 2 into tnumbera
put quote & "Col" & tnumbera & quote into tcola
put theDataA[tcola]

theDataA is the line data of a datagrid

If I use put theDataA["Col2"] ..... it returns the right value

but if I use put theDataA[tcola] ....... it doesn't return anything

Any idea what I am doing wrong ?

Kev

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Selecting a Datagrid column using a variable

Post by Zryip TheSlug » Sun Nov 27, 2011 11:54 pm

DukeUK wrote:I just can't get this to work.

I'm trying to get the contents of a datagrid cell from a column, where I use a variable to define the actual column.

This is the problem I'm having:

put 2 into tnumbera
put quote & "Col" & tnumbera & quote into tcola
put theDataA[tcola]

theDataA is the line data of a datagrid

If I use put theDataA["Col2"] ..... it returns the right value

but if I use put theDataA[tcola] ....... it doesn't return anything

Any idea what I am doing wrong ?
Hi Kev,

I think the problem should be on the line:

Code: Select all

put quote & "Col" & tnumbera & quote into tcola
Col2 is the name of the column in the datagrid. By quoting tcola, you will search for a column "Col2" in the datagrid. That's a bit different. ;)

Code: Select all

put 2 into tnumbera
put "Col" & tnumbera into tcola
put theDataA[tcola]
Note the existence of the GetDataOfLine or GetDataOfIndex functions in the datagrid API, for getting the content of a cell:
http://lessons.runrev.com/s/lessons/m/d ... or-Column-
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

DukeUK
Posts: 23
Joined: Sun Dec 06, 2009 5:55 pm

Re: Selecting a Datagrid column using a variable

Post by DukeUK » Mon Nov 28, 2011 10:56 pm

Many thanks

Yes without the quotes it all works fine.

Kev

Post Reply