Page 1 of 1

help with populating a datagrid form

Posted: Thu Jan 01, 2015 12:40 am
by jalz
Hi Guys,

I've got a datagrid form and have followed examples from the live code help/tutorial site. The dg form sorta looks like the way I want it, I'll need to do some tweaking to get it just the way I want, but I thin I can sort that out. I need help to format the data returned from a query so it goes into the dg form appropriately. I know the format of the output, however I don't know how to generate that type of output. Can someone help, if I list my code below. Label 2 is the title field and label 3 is the description field.

This is the code I have which works for a traditional table based datagrid.

Thanks all in advance.

Code: Select all

 if (gConnID > 0) then
      put "SELECT lineID, title, detail FROM myTbl WHERE ID =" && "'" & tID & "'" & "ORDER BY lineID" into tTheSQLQuery
      
      put revDataFromQuery(tab, cr, gConnID, tTheSQLQuery) into tTheData
      if tTheData begins with "revdberr," then
         delete item 1 of tTheData
      else
         --Below works for a table based datagrid with two columns
         --set the dgText[true] of me to "title" & tab & "detail" & cr & tTheData

         --I need to have output like the following to get the dg form to populate

         put "Lucky" into theDataA[1]["label 2"]
         put "Day" into theDataA[1]["label 3"]
         
         put "Dusty" into theDataA[2]["label 2"]
         put "Bottoms" into theDataA[2]["label 3"]
   
         lock screen
         set the dgData of group "dg_lines" to theDataA
       
         ## Hilite first row
         set the dgHilitedLines of group "dg_lines" to 1
         unlock screen
      end if
   end if

Re: help with populating a datagrid form

Posted: Thu Jan 01, 2015 6:49 pm
by jalz
Hi all,

I've solved my own problem, thought I would post it for anyone else that may have a similar query in the future.
To get the returned sql data into a format suitable for a datagrid FORM you need to create a multidimensional array. Obviously you're label 2, label 3 containers will most definitely be different to mine but you get the gist.

Code: Select all

         put 0 into tCounter
             
         set itemdel to TAB
             
         put empty into tDataA
             
         repeat for each line tLine in tSQLData
            add 1 to tCounter
            put item 1 of tLine into tDataA[tCounter]["Label 2"]
            put item 2 of tLine into tDataA[tCounter]["Label 3"]
         end repeat
         
         lock screen
         set the dgData of group "dg_lines" to tDataA
             
         ## Hilite first row
         set the dgHilitedLines of group "dg_lines" to 1
         unlock screen