DataGrid Calling handler to modify dgData
Posted: Thu May 15, 2014 8:44 am
I have to admit that I don't understand or get on with datagrids, they just have not clicked (yet?). One of my recent ones went wrong and I would like to know how I should have coded it and as an aside where I can find a definitive list of all the messages that are sent to datagrid group.
What went wrong: I wanted a simple datagrid to store connection settings, the last column is named 'selected' and is either true or false. The datagrid has five rows and I want the setting of a row to true to set all the other rows to false i.e. only a single row may be set to true. To make things look better and easier to use I made the selected column a checkbox. My plan was to store a reference to the row that the user had set to true, then set all the values to false then set the row just being edited back to true. I placed the following in the column behavior for the column named 'selected':
I now recognise that I should have used the dgindex of me rather than dgline of me. Anyway the routine UpdateDG does the following:
Now this worked for a time. Then things became a little odd, this same 'design' was being used in three different stacks and after a while the datagrid on all of them stopped calling the mouseup in the column behavior. In fact the IDE inspector while showing that a column behavior was present (the button in the inspector was enabled the plus button disabled) refused to open it for editing. Deleting the button did not work and in the end I just deleted the datagrid and managed the values 'true' / 'false' by hand.
Looking at the Datagrid documents I suspect that I may be guilty of editing the dgdata before the datagrid is ready. So where should I put my call?
Once I have made this post I intend trying to put the call to UpdateDg inside the On SelectionChanged in the group script of the datagrid. But as I really have no idea what I should be doing and have already managed to create self destructing code I thought I would ask how the experts would do it.
Sorry for a long post and thanks for reading,
best wishes
Simon K
What went wrong: I wanted a simple datagrid to store connection settings, the last column is named 'selected' and is either true or false. The datagrid has five rows and I want the setting of a row to true to set all the other rows to false i.e. only a single row may be set to true. To make things look better and easier to use I made the selected column a checkbox. My plan was to store a reference to the row that the user had set to true, then set all the values to false then set the row just being edited back to true. I placed the following in the column behavior for the column named 'selected':
Code: Select all
On mouseUp
-- call routine on the card params name of dg, row data, theline number I think
send "UpdateDG the dgControl of the target, the dgData of the target, the dgline of me" to card "dbsettings" in 0
end mouseUp
I now recognise that I should have used the dgindex of me rather than dgline of me. Anyway the routine UpdateDG does the following:
Code: Select all
On UpdateDG pDgName,pDataA, pRowNo
lock screen
# set all the values of selected to false
repeat for each key tkey in pDataA
put false into pDataA[tkey]["selected"]
end repeat
# set the row of interest to true
put true into pDataA[pRowNo]["selected"]
answer pDgName
set the dgData of pDgName to pDataA
unlock screen
end UpdateDG
Looking at the Datagrid documents I suspect that I may be guilty of editing the dgdata before the datagrid is ready. So where should I put my call?
Once I have made this post I intend trying to put the call to UpdateDg inside the On SelectionChanged in the group script of the datagrid. But as I really have no idea what I should be doing and have already managed to create self destructing code I thought I would ask how the experts would do it.
Sorry for a long post and thanks for reading,
best wishes
Simon K