(data grid) is there a good workaround for obtaining other column values in FillInData for a Data Grid Table?

zryip theSlug zryip.theslug at gmail.com
Thu Aug 19 05:47:05 EDT 2010


On Thu, Aug 19, 2010 at 1:48 AM, Josh Mellicker <josh at dvcreators.net> wrote:
>>> If you set a custom behavior for the column you want the sum in, and
>>> where it has the section for filling data, put
>>>
>>>  put the dgDataOfIndex[ the dgIndex of me] of the dgControl of me
>>> into theDataA
>>>  set the text of field 1 of me to (theDataA["Col 2"] + theDataA["Col 3"])
>>>
>>> Should work fine. Not positive this is the best method, but seems to
>>> work dandy fine with small datasets.  Haven't tried it with big ugly
>>> datasets.
>>
>> If you didn't want to fetch all of the data for the entire row you could use GetDataOfIndex. GetDataOfIndex only retrieves the value of a specific column.
>>
>> put the dgIndex of me into theIndex
>> set the text of field 1 of me to (GetDataOfIndex(theIndex, "Col 2") + GetDataOfIndex(theIndex, "Col 3"))
>
>
> And this code goes into FillInData in the table's behavior, right?

You have two options:
- change the script in the column behavior for the column you want to
display a sum.
- or define a default column behavior for the datagrid


If you choose the first option, change your script with a code like this:

on FillInData pData
   local tTheIndex

   put the dgIndex of me into tTheIndex
   put sumOfColumn(tTheIndex,"Col2","Col3") into pData
   set the text of the long id of me to pData

end FillInData

function sumOfColumn pTheIndex
   local tTheSum

   put 0 into tTheSum

   repeat with x = 2 to the paramcount
      add GetDataOfIndex(pTheIndex,param(x)) to tTheSum
   end repeat

   return tTheSum
end sumOfColumn


If you prefer the second solution, you're welcome to download and use
the code of the sample stack I proposed in my first reply ;)

Regards,
-- 
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc



More information about the use-livecode mailing list