Updating a data grid

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

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Updating a data grid

Post by tyarmsteadBUSuSfT » Sun Jan 05, 2014 5:35 pm

I've wrestled with this for a while and can't see what is wrong. I'm trying got update a data grid with:
on FillInData pDataArray
set the text of field "EntryDate" of me to pDataArray[x]["label 5"]
set the text of field "lon" of me to pDataArray[x]["label 9"]
set the text of field "lat" of me to pDataArray[x]["label 10"]
set the text of field "Category" of me to pDataArray[x]["category"]
set the text of field "ItemName" of me to pDataArray[x]["itemname"]
set the text of field "ItemDesc" of me to pDataArray[x]["label 3"]
set the hilited of button "save location" of me to (pDataArray[x]["label 11"] is "true")
set the hilited of button "HIgh Rank" of me to (pDataArray[x]["label 6"] is "true")
set the hilited of button "Med Rank" of me to (pDataArray[x]["label 7"] is "true")
set the hilited of button "Low Rank" of me to (pDataArray[x]["label 8"] is "true")
set the text of field "Seq Numb" of me to pDataArray[x]["label 14"]
lock screen
set the dgData of group "wishlist" of card "wishlistCard" to pDataArray
set the dghilitedLines of group "wishlist" of card "wishlistcard" to 1
unlock screen
I can see the Array list but not update the template. The fields are mapped to the array.
Please help, I know it is right in front of me, but I just can't see it.
Thanks
Ty

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Sun Jan 05, 2014 5:51 pm

Hi Ty,

pDataArray is a ONE dimensional array (the current index!), so leave out the [x] and all should be fine:

Code: Select all

on FillInData pDataArray
  set the text of field "EntryDate" of me to pDataArray["label 5"]
  set the text of field "lon" of me to pDataArray["label 9"]
  ## etc...
end FillInData

Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Sun Jan 05, 2014 6:26 pm

Klaus,
It looks like on of those dense days as I'm still doing something incorrectly.
I create the array from a text file in the preopencard
put url ("file:" & specialFolderPath("documents") & "/ItemList.txt")  into tItem
put tItem into pDataArray
split PDataArray by return and tab
I've tried to dispatch it to the group with the same results.
then map it with the label and file of the data grid in the fillindata script portion an am still getting a empty return.
Thanks for the help
Ty

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Sun Jan 05, 2014 6:32 pm

Can you post some lines of that TXT file?
I am not sure if using split will produce the correct format for the dg array!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Sun Jan 05, 2014 6:35 pm

Quick questions:
1. You do have that FillInData handler in the ROW BEHAVIOR of the datagrid, right?
2. the datagrid you are trying to update is NOT this one (hopefully) -> group "wishlist" of card "wishlistCard"

No idea what this line actualy does:
...
set the dgData of group "wishlist" of card "wishlistCard" to pDataArray
...
This will that datagrid for EVERY index repeat loop anew!?

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Sun Jan 05, 2014 7:29 pm

1388713620 Table Set A wood table seet with chairs No Date Table and chairs Not Lat No Long No Picture false true false false 1/2/14 8:47:55 PM
1388713680 lamps set gold lamps set No Date lamps and stuff Not Lat No Long No Picture true false false false 1/2/14 8:48:21 PM
1388713680 wood table oak table with center leaf No Date table Not Lat No Long No Picture true false false false 1/2/14 8:48:46 PM

The script was generated though the data grid helper and I modified it.
Yes it is wish list of card wishlistcard, that must be a problem.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Sun Jan 05, 2014 7:56 pm

Please answer question 1, most important!

If that is really the dataqgrid then your are somehow updating the dategrid
while updateing the same datagrid(?), which cannot be healthy :D

it might be a good idea to go through the complete datagrid PDF to get the basics
of datagrids, which ARE in fact highly complex!
http://lessons.runrev.com/m/datagrid


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Sun Jan 05, 2014 10:38 pm

Yes, it is in the row behavior script.
So it appears that I am updating twice?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Sun Jan 05, 2014 11:30 pm

Hi Ty,
tyarmsteadBUSuSfT wrote:Yes, it is in the row behavior script.
:shock:
tyarmsteadBUSuSfT wrote:So it appears that I am updating twice?
Yep, even more -> (the number of keys of the dg array) times!

In any case remove these lines from your script:
...
lock screen
set the dgData of group "wishlist" of card "wishlistCard" to pDataArray
set the dghilitedLines of group "wishlist" of card "wishlistcard" to 1
unlock screen
...
"FillInData" is part of the "command chain" that is invoked when you "set the dgdata of grp xyz to ..."!
So I really wonder why you did not get a "recursion limit" error!? :D


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Mon Jan 06, 2014 3:44 pm

Klaus,
I have gone through the tutorial multiple times, but will walk thought it again.
Thank you for your help
Ty

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Mon Jan 06, 2014 7:40 pm

Still can get it to populate the data grid.
What I am doing is creating a text file and then using the data from the text file with multiple lines (tab delim) to create the array. I then need to populate the data grid. I've gone round and round on this to point I'm really confused. I have review the tutorial serval times to no avail. the tutorial: http://lessons.runrev.com/s/lessons/m/d ... -of-people using the set the data control seems to be what I want to do, yet I still can not get it to work. Any arise would be greatly appreciated.
Thank you
Ty

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Mon Jan 06, 2014 7:49 pm

Hi Ty,

please post the code you use to create an ARRAY from your TAB delimited file!


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Mon Jan 06, 2014 9:43 pm

(I've tried with and without the [x])
I can see the data in the "show data" option in the data grid helper

set itemDel to tab
put url ("file:" & specialFolderPath("documents") & "/ItemList.txt")  into tItem
put tItem into pDataArray
----I have also tried it with and without the split

split PDataArray by return and tab
get number of lines of tItem
put it into tNumbLines
repeat with x = 1 to the number of lines of tItem
put item 5 of line x of tItem into pDataArray[x]["Category"]
put item 2 of line x of tItem into pDataArray[x]["ItemName"]
put item 3 of line x of tItem into pDataArray[x]["label 3"]
put item 4 of line x of tItem into pDataArray[x]["label 5"]
put item 6 of line x of tItem into pDataArray[x]["label 10"]
put item 7 of line x of tItem into pDataArray[x]["label 9"]
end repeat
dispatch AddData to group "WishList" of card me with pDataArray

Thank you,
Ty

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Updating a data grid

Post by Klaus » Mon Jan 06, 2014 11:18 pm

Hi Ty,

ah, oh, I see :D
Is this a "mouseup" script?

OK, here some working code:

Code: Select all

...
set itemDel to tab
put url ("file:" & specialFolderPath("documents") & "/ItemList.txt")  into tItem

## Don't:
## put tItem into pDataArray
## split PDataArray by return and tab 
## This will "spoil" the ARRAY that you are building below!

## get number of lines of tItem
## put it into tNumbLines

## This will create an array in the correct format for the datagrid:
repeat with x = 1 to the number of lines of tItem
  put item 5 of line x of tItem into pDataArray[x]["Category"]
  put item 2 of line x of tItem into pDataArray[x]["ItemName"]
  put item 3 of line x of tItem into pDataArray[x]["label 3"]
  put item 4 of line x of tItem into pDataArray[x]["label 5"]
  put item 6 of line x of tItem into pDataArray[x]["label 10"]
  put item 7 of line x of tItem into pDataArray[x]["label 9"]
end repeat

## OK, ARRAY is ready, now we "fill" the datagrid with data:
set the dgdata of grp  "WishList" to pDataArray
## DONE! :D 
...
##dispatch "AddData" to group "WishList" of card me with pDataArray
"addata" will ADD data to an exitsing datagrid but will NOT accept
a multidimensional array, since it is only meant to add ONE record.

And "... of card me" is invalid syntax!
You can use "... of THIS cd" or, if it is in the card script: "... of ME"


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Updating a data grid

Post by tyarmsteadBUSuSfT » Tue Jan 07, 2014 12:42 am

Actually it was to set the array in the preopencard and pass to the fillindata of the data grid.
Ty

Post Reply