Populating a Data Grid with Array Data

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Colorado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6
Joined: Thu Jan 27, 2011 7:03 am

Populating a Data Grid with Array Data

Post by Colorado » Fri Aug 05, 2011 9:11 am

I have been unable to figure out how to get data from an array into a data grid. The array consists of 18 "records". There are 18 keys, each being a student's name. For each student (key) there are 5 elements (scores). I can look at the variable list for the array and it can be expanded to show the student names (keys) and each of those can be expanded to show the 5 scores (elements) for each, so I know the array works. Each element is named and the names appear perfectly, along with their values (scores) in the variable listing.

I have a created data grid that consists of 18 rows and 7 columns. The columns are all named. The first column is "Name" and I would like to populate each row in that column with the key (student's name). The next 5 columns are scores for different subjects (these are the named elements following each key). The last column is labeled "Total" and I would like to add up all 5 scores for the student and put the sum there.

I have been completely unable to figure out how to get the array data into the data grid. It seems like it shouldn't be so hard to do.

Any help would be most appreciated.

Colorado

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

Re: Populating a Data Grid with Array Data

Post by dunbarx » Sat Aug 06, 2011 11:23 pm

Hi. If you have a datagrid (group "yourDG")

Make an array, set a datagrid property ("the dgText") on your datagrid :

Code: Select all

on mouseUp
   repeat with y = 1 to 4
      put random(99) into myArray[y]
   end repeat
   combine myArray with return and tab
   set the dgText of group "yourDG" to myarray
end mouseUp
But do go here:

http://lessons.runrev.com/spaces/lesson ... With-Data-

Craig Newman

Colorado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 6
Joined: Thu Jan 27, 2011 7:03 am

Re: Populating a Data Grid with Array Data

Post by Colorado » Tue Aug 09, 2011 11:27 pm

Craig,

Thanks so much for your response to my query. My problem seemed to be that I used a name for a key and not a (line) number. I converted my array to use numbers as keys and then used "set dgData..." and got it working. Now I am trying to format the cells to be just 2 decimal places and I am just starting to get into the fillInData function.

Is there any way to fill in a data grid using something other than a number as a key? I tried everything but never got it to work. The code I added to put the numbers as keys is a bit of a kludge so I would like a purer solution if one is possible.

Colorado

Post Reply