Page 1 of 1

DataGrid Message not ExitField

Posted: Fri Jun 17, 2011 6:53 pm
by townsend
This is like the third time I've needed to do this.
I suspect there is no easy answer, but I have to ask.

When a user edits a DataGrid cell with a double click,
what's the Message event that is generated AFTER completion?

I've tried everything I can think of.
Reference: Data Grid API w/ Messages Sent

Re: DataGrid Message not ExitField

Posted: Fri Jun 17, 2011 7:40 pm
by bangkok
on CloseFieldEditor pFieldEditor
put the dgColumn of the target into theColumnBeingEdited
put unidecode(the unicodetext of pFieldEditor, "UTF8") into theNewText
end CloseFieldEditor

Re: DataGrid Message not ExitField

Posted: Fri Jun 17, 2011 8:02 pm
by townsend
I've got a nice little routine that does column totals:

Code: Select all

 on doTotals
     put empty into field total.qty
     put empty into field total.value
     repeat with ii = 1 to the dgNumberOfLines of group mygrid
          put the dgDataOfLine[ii] of group mygrid into theDataA
          put theDataA["Qty"]  + field total.qty into field total.qty
          put theDataA["Value"]  + field total.value into field total.value
     end repeat
end doTotals
When I put my call to doTotals in the CloseFieldEditor routine, the DataGrid
has yet to be updated, and my total for that column ends up wrong.

I guess there is no real AFTER message event.
Is there some way I can force an update before the end CloseFieldEditor???
That would be nice.

Otherwise this code does work:

Code: Select all

on CloseFieldEditor
     send "dototals" to me in 0.2 seconds
end CloseFieldEditor
Thanks for you help on this bangkok!

Re: DataGrid Message not ExitField

Posted: Fri Jun 17, 2011 8:54 pm
by bangkok
Ah okay.

In this case, it's very simple.

You have to modify the "defaut column" script.
http://tinyurl.com/3rnhpxv

and put your calculation into the FillInData handler.

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   
   set the text of me to pData

---- do your calculation
end FillInData

Re: DataGrid Message not ExitField

Posted: Sat Jun 18, 2011 12:29 am
by townsend
I went to that Lesson you suggested, on overriding behavior for column cells.
Wow-- I must say-- I've been actively working with LiveCode for about three months,
and I'm continually impressed with how well everything fits together.
This is the first time I've thought, this doesn't seem right.

That is-- to control DataGrid column behavior, it looks like you need to create a Button then link the Button to the DataGrid. That does seem odd. It would make much more sense to just have all these extra Handlers in the DataGrid code itself.

Before going this route, I thought I'd try something else, which almost seems to work. This code is placed directly in the DataGrid. It prevents a double click edit on the cell AND presents an ASK window instead.

Code: Select all

on editcellofindex tName tRow
     put the dgDataOfLine[tRow] of group mygrid into theDataA
     ask "Enter New Value:" with theDataA[tName] titled theDataA[tName]
     if the result is "Cancel" then
     else
          SetDataOfIndex the tRow of me, theDataA[tName], it
          refreshIndex the tRow of me
     end if
end editcellofindex
The Ask box sometimes gets mixed up and returns the wrong row.
The SetDataOfIndex command never works. Is this a totally far fetched
use of the EditCellOfIndex Message event? Or could this be a viable solution?

Re: DataGrid Message not ExitField

Posted: Sat Jun 18, 2011 9:06 am
by bangkok
townsend wrote: That is-- to control DataGrid column behavior, it looks like you need to create a Button then link the Button to the DataGrid. That does seem odd. It would make much more sense to just have all these extra Handlers in the DataGrid code itself.

Before going this route, I thought I'd try something else, which almost seems to work. This code is placed directly in the DataGrid. It prevents a double click edit on the cell AND presents an ASK window instead.
Well it might sounds strange, but it's working very well. You'll see, you'll get used to it.

The advantage of the column defaut script is that you go to the "core". So it's much easier/cleaner to do what you want to achieve (an action after the edition of a cell and the update of the whole grid).
It's perfect for instance to change the apparence of a line, lets say its background color linked to a certain value in a column etc.

The solution of an "ask" window to input data in a cell is not very elegant.

You might want to download an example :

Here :
http://forums.runrev.com/viewtopic.php? ... 65&start=0