Saving updated data from a datagrid table
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Saving updated data from a datagrid table
Hi,
I have just spent some time going around in circles so I hope that someone can help me out. I have a custom stack property that holds tab delimited data loaded from a file. I wish to view and edit the data so have copied it into a datagrid table. The default datagrid settings allow me to edit the data and I can save the data back to the custom property by using the the dgtext property. So far so good.
My problems started when I decided that it would be a good idea if edits to the datagrid data were saved automatically once the user exited the cell. I have tried intercepting the closefieldeditor message but I don't seem to be able to pass the message on so that the edit completes. I have also tried creating a custom behavior as described in the documentation (page 147) but this just disables any editing.
What am I doing wrong and what is the simplest method of saving the data?
many thanks
Simon
I have just spent some time going around in circles so I hope that someone can help me out. I have a custom stack property that holds tab delimited data loaded from a file. I wish to view and edit the data so have copied it into a datagrid table. The default datagrid settings allow me to edit the data and I can save the data back to the custom property by using the the dgtext property. So far so good.
My problems started when I decided that it would be a good idea if edits to the datagrid data were saved automatically once the user exited the cell. I have tried intercepting the closefieldeditor message but I don't seem to be able to pass the message on so that the edit completes. I have also tried creating a custom behavior as described in the documentation (page 147) but this just disables any editing.
What am I doing wrong and what is the simplest method of saving the data?
many thanks
Simon
best wishes
Skids
Skids
Re: Saving updated data from a datagrid table
Hi Simon,
we can only guess without looking at your script(s)!
Maybe you just left a "pass XYZ" in your custom behavior script?
Best
Klaus
we can only guess without looking at your script(s)!
Maybe you just left a "pass XYZ" in your custom behavior script?
Best
Klaus
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Saving updated data from a datagrid table
Using the following code snips disabled default field editing in my datagrid.
from the DG group:
The code in the button referenced above:
from the DG group:
Code: Select all
on preOpenFieldEditor pFieldEditor
set the behavior of pFieldEditor to the long ID of btn "CustomFieldEditorBehavior"
end preOpenFieldEditor
On StoreICDDataGrid
put "StoreICDDataGrid has fired"
// Store the datagrid to the custom function
set c138Fields of stack "ICDdataDescription" to dgtext of group "dglists"
put "data stored"
end StoreICDDataGrid
Code: Select all
--> all handlers
on escapeKey
send "DeleteFieldEditor false" to the dgControl of me in 0 seconds
end escapeKey
on closeField
## Don't delete editor within same message
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
end closeField
on exitField
Call StoreICDDataGrid
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
end exitField
on returnInField
if the autotab of me then
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
else
pass returnInField
end if
end returnInField
on enterInField
if the autotab of me then
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
else
pass enterInField
end if
end enterInField
on tabKey
if the autotab of me then
send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
else
pass tabkey
end if
end tabKey
on selectionChanged
## don't pass as selectionChanged is reserved for group
## developer can override behavior to process selectionChanged
end selectionChanged
best wishes
Skids
Skids
Re: Saving updated data from a datagrid table
Hi Simon,
looks OK, but "call" is probably the troublemaker!
And some missing "the"s
Put this handler into the stack or card script:
And change this:
Best
Klaus
looks OK, but "call" is probably the troublemaker!
And some missing "the"s

Put this handler into the stack or card script:
Code: Select all
command StoreICDDataGrid
put "StoreICDDataGrid has fired"
set THE c138Fields of stack "ICDdataDescription" to THE dgtext of group "dglists"
put "data stored"
end StoreICDDataGrid
Code: Select all
on exitField
## "call" this handler by just its name ;-) ## Check "call" in the dictionary!
StoreICDDataGrid
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
end exitField
Klaus
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Saving updated data from a datagrid table
Hi Klaus,
I have managed to get it working and the main problem was the location of my behavior button. Basically the only way to get it to work was to place the button on the same stack as the datagrid.
I seem to be having similar problems with setting the default column behavior; I have followed the guide and proved that my datagrid is set to use my behavior button (by using code to retrieve the default column behavior) but I am unable to get the grid to fire any of the routines. I have littered the copy of the default code with indicators to try and prove it is working, it is not
I'm wondering if I should cut my losses and revert to a "Basic Table Field"
best wishes
Simon
I have managed to get it working and the main problem was the location of my behavior button. Basically the only way to get it to work was to place the button on the same stack as the datagrid.
I seem to be having similar problems with setting the default column behavior; I have followed the guide and proved that my datagrid is set to use my behavior button (by using code to retrieve the default column behavior) but I am unable to get the grid to fire any of the routines. I have littered the copy of the default code with indicators to try and prove it is working, it is not

Code: Select all
--> all handlers
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 the long ID of me to pData ## temp workaround for
TruncateTail the short id of me, "..."
end FillInData
on LayoutControl pControlRect
-- A default column is just a field. Nothing to change here.
TruncateTail the short id of me, "..."
end LayoutControl
on ResetData
-- Sent when column data is being emptied because the control is no longer being used to display data
set the text me to empty
end ResetData
on PreFillInData
-- Sent right before new data is going to replace existing data in the column
beep
put "prefill in data fires" & cr after fld"debug"
end PreFillInData
setprop dgHilite pBoolean
-- This custom property is set when the highlight of your column template has
-- changed. You only add script here if you want to customize the highlight.
beep
put "dghilite has fired" & cr after fld"debug"
answer "dghilite firse"
if pBoolean then
set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundColor of me to empty
end if
end dgHilite
getprop dgDataControl
-- Required by library so that it can locate the control.
return the long ID of me
end dgDataControl
-- Data grid will call this if a user action asks to edit cell content.
command EditValue
put "Edit Value has fired " & cr after fld"debug"
EditFieldText the long ID of me, the dgIndex of me, the dgColumn of me
end EditValue
on mouseDoubleUp pMouseBtnNum
put "mouse double up has fired" & cr after fld"debug"
if pMouseBtnNum is 1 then
if the dgProps["allow editing"] of the dgControl of me \
and the dgColumnIsEditable[the dgColumn of me] of the dgControl of me then
-- Edit field contents if the user double-clicks
EditCellOfIndex the dgColumn of me, the dgIndex of me
exit mouseDoubleUp
end if
end if
pass mouseDoubleUp
end mouseDoubleUp
best wishes
Simon
best wishes
Skids
Skids
-
- Posts: 919
- Joined: Wed Nov 04, 2009 11:41 am
Re: Saving updated data from a datagrid table
Hi,
Grasping at straws I re-installed Livecode (4.6) and the datagrid started using my behavior script.
Simon
Grasping at straws I re-installed Livecode (4.6) and the datagrid started using my behavior script.
Simon
best wishes
Skids
Skids