(DataGrid) is there a message when the user has edited a cell ?
zryip theSlug
zryip.theslug at gmail.com
Fri Jul 9 15:29:48 EDT 2010
You forget nothing André, but I have forget something in my previous script!
;)
In fact the new value edited in a cell will be updated in the data of the
column after the execution of the closeFieldEditor.
So when we execute the sum, the uSumOfColumn will take the old value of the
cell, not the update value.
For doing the task I propose two solutions :
1) Doing the sum outside the closeFieldEditor
In the script of the DataGrid, add this handler
on doSum
set the text of fld "fldTotSum1_1" to the uSumOfColumn["Sum
1"] of the dgControl of me
set the text of fld "fldTotSum2_1" to the uSumOfColumn["Sum
2"] of the dgControl of me
end doSum
In the behavior of the two columns update the closeFieldEditor like this:
on CloseFieldEditor pFieldEditor
send "doSum" to the dgControl of me in 0 secs
end CloseFieldEditor
Note we have to send the "doSum" event with a delay to execute the sum in
time ;).
2) For doing the sum inside the CloseFieldEditor we have to store the value
of the column in the data of the column ourself.
For doing that, update the closeFieldEditor like this:
on CloseFieldEditor pFieldEditor
## This part of the script store the new value of the cell in the data
put the dgIndex of me into theIndex
put the dgDataOfIndex[theIndex] of the dgControl of me into theDataA
put the text of pFieldEditor into theDataA[the dgColumn of me]
set the dgDataOfIndex[theIndex] of the dgControl of me to theDataA
## This part of the script update the sums
set the text of fld "fldTotSum1_2" to the uSumOfColumn["Sum
1"] of the dgControl of me
set the text of fld "fldTotSum2_2" to the uSumOfColumn["Sum
2"] of the dgControl of me
end CloseFieldEditor
To answer a question I missed from you, the pFieldEditor contains a
reference to the cell in edition in the grid. Its like a field if you
prefer, and you can read the current value in it. It could be only a cell in
edition in a Grid.
To simplify the experiment, I create a small demo stack. Be free to play
with it and use the scripts for your own needs ;)
You can download the sum stack by following this link:
exp 012_sum_in_dg.rev.zip<http://www.aslugontheroad.co.cc/index.php?option=com_phocadownload&view=category&download=5:experiment-012-doing-sum-in-a-data-grid&id=1:developers-tricks&Itemid=63>
Regards,
--
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc
More information about the use-livecode
mailing list