Page 1 of 1

Getting data from a Data Grid

Posted: Thu Mar 20, 2014 11:10 am
by snappy
Hi,

I've done several hours of searching but I can't seem to solve this problem:

I want to get data from a field in a Data Grid and pass it into a text field on another card in another stack.

I can't seem to figure out how to do that. Any ideas?

I should also say that I'm using the Data Grid as a resource only. The user never interacts with it.

Thanks,
snappy

Re: Getting data from a Data Grid

Posted: Thu Mar 20, 2014 11:45 am
by MaxV
Use the dgData property, it's just an arrya:
dgData
Usage:

Code: Select all

get the dgData
set the dgData of group "DataGrid" to pDataArray
Get or set the data array that the data grid will display. The array organization is the following: dgData[row][column_name], where row is an integer and column_name is a string. The first dimension of the array uses numeric keys and the value of each is an array. You can store anything you would like in each numeric key's array. For data grid tables the keys should match the column names in order for the data grid to correctly map the array value to the column cell. The following array would represent two records in the data grid:

Code: Select all

put "Hi" into theA[1]["message"]
put "Bye" into theA[2]["message"]
set the dgData of group "DataGrid" to theA
:wink:

Re: Getting data from a Data Grid

Posted: Thu Mar 20, 2014 1:27 pm
by dunbarx
What MaxV said.

Note that you can also extract data in the clear by using the "dgText" property. This gives a tab and return delimited data set.

You have to start using the DataGrid manual. This can be found here:

http://lessons.runrev.com/m/datagrid

Craig Newman

Re: Getting data from a Data Grid

Posted: Fri Mar 21, 2014 8:15 am
by snappy
Thanks, guys.

I clearly need to learn more. I'm not sure how to apply your information. I started on LiveCode last year but let my knowledge lapse.

I'm still trying to learn the basics. Might be getting ahead of myself, here.

Re: Getting data from a Data Grid

Posted: Fri Mar 21, 2014 10:14 am
by MaxV
For example you have a datagrid called "mytable", this datagrid has 2 columns named "myFirstCol" and "mySecondCol". If you want to know the value of the cell in the second row and second column you just type:

Code: Select all

put the dgData of group "mytable" into temp
put temp[2]["mySecondCol"]
See also http://livecode.wikia.com/wiki/Arrays