Get Data from another Column - Data Grid

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
FinishTheCode
Posts: 5
Joined: Wed Apr 17, 2013 3:53 pm

Get Data from another Column - Data Grid

Post by FinishTheCode » Fri Apr 19, 2013 3:28 pm

I am really struggling with Data Grids.

If a line of data is selected in a data grid, how do I get a particular piece of data from one of the columns.

For example if i had this

Column 1 - Worker Type
Column 2 - Normal Cost Per Hour
Column 3 - After Hour Cost Per Hour
Column 4 - Weekend Cost Per Hour

If that row was selected, how would I get the data from column 4 and put it into a text field.

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

Re: Get Data from another Column - Data Grid

Post by dunbarx » Fri Apr 19, 2013 3:56 pm

Hi.

Everyone struggles with datagrids until you get used to them. Then you struggle some more. But they are tremendous.

There are many ways to do this. Select a line in the DG. In a button script, try:

Code: Select all

on mouseUp
   put the dgHilitedLine of grp yourDG into tLine
   get the dgDataOfline[tLine] of grp yourDG
   combine it with return and tab
   answer it
end mouseUp
You can now extract whatever you want from that line.

Or, how about this for brevity:

Code: Select all

on mouseup
answer line (the dgHilitedLine of grp yourDG) of the dgText of grp yourDg
end mouseup
Craig Newman

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Get Data from another Column - Data Grid

Post by snm » Sat Apr 20, 2013 1:41 pm

Put script:

Code: Select all

on dgMouseUp
   local tLine
   
   put the dgHilitedLine of grp "myDataGrid" into tLine
   get the dgDataOfline[tLine] of grp "myDataGrid"
   put it["Col 4"] into fld "myField"
end dgMouseUp
as your DataGrid group script (must change the name of DataGrid used in this script to the name of your DataGrid group).

It should do exactly what you asked.

Marek

Post Reply