DataGrid Form Repeat FillInData problem (Database)

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
newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

DataGrid Form Repeat FillInData problem (Database)

Post by newpie » Sat Feb 20, 2016 9:35 pm

Hello, I am sure I am missing something simple with this, but hope someone could guide me in correct direction:

I get my result from the database which I verified is working correctly. I then use the following code in my card script:

Code: Select all

      repeat for each line tmyLine in tRecords
         add 1 to theLine
         put item 1 of tmyLine into theDataA[theLine]["Var1"]
         put item 2 of tmyLine into theDataA[theLine]["Var2"]
         put item 3 of tmyLine into theDataA[theLine]["Var3"]
         dispatch "AddData" to group "DataGrid 1" with theDataA, theLine
         put the result into theNewIndex -- integer if successful, error string otherwise
      end repeat
I confirm that the Array is being built correctly, the issue is filling it in on the form. It is creating each record on the form, but only the static fields are coming thru (template).
My group row template matches the above values as well.

I have this code in the Row Behavior:

Code: Select all

on FillInData pDataArray
   set the text of field "Var1" of me to pDataArray["Var1"]
   set the text of field "Var2" of me to pDataArray["Var2"]
   set the text of field "Var3" of me to pDataArray["Var3"]
end FillInData

Code: Select all

on LayoutControl pControlRect
   local theFieldRect
   set the rect of graphic "Background" of me to pControlRect
end LayoutControl
Any help would be appreciated, thanks.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: DataGrid Form Repeat FillInData problem (Database)

Post by sritcp » Sat Feb 20, 2016 9:57 pm

Hi newpie:

1. AddData is used to add (i.e., insert) data into a datagrid after you have already populated the datagrid. Is this true in your case?

2. theData in your example should be a 1-dimensional array, not 2D. So, use

Code: Select all

put item 1 of tmyLine into theDataA["Var1"]
.......
.......
3. theLine in your dispatch statement refers to the line number of the datagrid at which this data will be INSERTED; the current line number theLine will be pushed down one row. Is this what you want?
If you want to add the new data to the end of the datagrid, omit the theLine argument.
If you want to replace the current data in a datagrid row, use setDataOfLine or, better, setDataOfIndex commands.

Please refer to the datagrid api in the datagrid manual.

Regards,
Sri

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: DataGrid Form Repeat FillInData problem (Database)

Post by newpie » Sat Feb 20, 2016 10:09 pm

Thank you Sri, that worked great. I did try to search the forums and look thru the tutorials, but couldn't find what i needed. I will look thru API as well.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: DataGrid Form Repeat FillInData problem (Database)

Post by quailcreek » Sun Feb 21, 2016 1:58 am

So are you pulling multiple lines of data from the Db and putting them into your DG? If so you should look at something like this.
Instead of doing a dispatch of each line. This way you don't need the counter either.

Code: Select all

repeat with x = 1 to the num of lines of tRecords
   put item 1 of line x of tRecords into theDataA[x]["Var1"]
   put item 2 of line x of tRecords into theDataA[x]["Var2"]
   put item 3 of line x of tRecords into theDataA[x]["Var3"]
end repeat

if theData is not empty then set the dgData of grp "DataGrid 1" to theDataA
Tom
MacBook Pro OS Mojave 10.14

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: DataGrid Form Repeat FillInData problem (Database)

Post by newpie » Sun Feb 21, 2016 2:48 am

Ok quailcreek, I will try this and see if it is more efficient than previous method. I appreciate the comment.

Post Reply