Pass form row data from datagrid to a set of fields

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Pass form row data from datagrid to a set of fields

Post by jalz » Tue Apr 22, 2014 3:07 pm

Hi all,

Sorry It’s me and datagrids again :? . I have a datagrid setup as a form. The form has 4 fields to it, description, price, qty, line_total. The description field contains html text such as for e.g.
<p>Fees for Schools</p>
<p><b>Academic Year 2013-2014</b></P>
<p>Please note…….</p>

There maybe more then one row of data in the datagrid containing html text in the description. I am trying to pass the 'complete' data of each field to another layout which contains a group of controls. I was using the following command which I thought was working initially until I looked at it closer and realised it was only pulling out a single line of data at a time

put the DgText of grp "myGrid" into ... d repeat

I’ve narrowed down the problem to the repeat chunktype I am using is for a table based datagrid with single lines. I need to use a different chunktype in my repeat control structure. So researching, I found quite a useful tutorial explaining chuncktypes http://lessons.runrev.com/s/3527/m/4603 ... -with-text. I think I should be using <b>repeat for each item tLine in tGrid</b> to remove the contents of an entire field, however although this is extracting the entire contents of description as I want, I’m having difficulty keeping the price, qty, line_price in the same row on the layout Im trying to pass the data through.

Is there an easy way to solve this one? Off to do more reading, I’m sure someone else must have encountered this?

Thanks
Jalz

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

Re: Pass form row data from datagrid to a set of fields

Post by Klaus » Tue Apr 22, 2014 3:24 pm

Hi Jalz,
I was using the following command which I thought was working initially
until I looked at it closer and realised it was only pulling out a single line of data at a time
the script is in fact processing ALL lines of your datagrid, but will overwrite the content of your fields
in every repeat loop, so only the data of the LAST line of your dg will finally be in your fields.

But to be honest, I have no idea what your actual question is! :D


Best

Klaus

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Pass form row data from datagrid to a set of fields

Post by jalz » Tue Apr 22, 2014 3:44 pm

Hi Klaus,

I’ll try and explain better hopefully, In a nutshell, my dg contains the following data

ignore the table, I was trying to lay the data out, didnt realise the forum didn't recognise table tags
<table>
<tr>
<td>Fees for School<br />
Academic Year 2013-2014<br />
Please note....</td>
<td>1,000</td>
<td>3</td>
<td>3,000</td>
</tr>
<tr>
<td>Uniform</td>
<td>80</td>
<td>1</td>
<td>80</td>
</tr>
</table>

When I use the following code to extract the entire row data

Code: Select all

   repeat for each line tLine in tGrid
      
      set the htmltext of field "description" to item 1 of tLine
      set the text of field "price" to item 2 of tLine
      set the text of field "qty" to item 3 of tLine
      set the text of field "line_price" to item 4 of tLine
    end repeat
It extracts the following data (its missing line 2 and 3.. from the initial description box)
Fees for School 1,000 3 3,0000

I would like a way to extract the entire content of a row if that makes sense (i.e. all the lines/content from the description field) and paste it in another field object.

I’m not sure I’ve done a better job, I think I might have to upload a stack to show you what I mean?

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

Re: Pass form row data from datagrid to a set of fields

Post by Klaus » Tue Apr 22, 2014 4:18 pm

AH! Now I get it, your dg is a FORM!
Completely overlooked this important info! 8)

Well, then "the dgtext" will not work, since this will NOT support multiline items!
Use "the dgdata" of the dg, which is an array and you can access the keys separately if necessary:

Code: Select all

...
## Accessing the first index of that array:
put the dgdata of grp "your datagrid here..." into tData
put 1 into tIndex

## Now use ARRAY syntax to "pull" out your data:
set the htmltext of field "description" to tData[tIndex]["name of first column here..."]
set the text of field "price" to tData[tIndex]["name of second column here..."]
set the text of field "qty" to tData[tIndex]["name of third column here..."]
## etc., you get the picture
...
Best

Klaus

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Pass form row data from datagrid to a set of fields

Post by jalz » Tue Apr 22, 2014 6:37 pm

Thank you Klaus, that nailed it :)

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

Re: Pass form row data from datagrid to a set of fields

Post by Klaus » Tue Apr 22, 2014 6:55 pm

jalz wrote:Thank you Klaus, that nailed it :)
Call me "Hammer"! :D

Post Reply