popup-/contextmenu in Editor field of DataGrid?
Trevor DeVore
lists at mangomultimedia.com
Fri Sep 11 08:43:41 EDT 2009
On Sep 11, 2009, at 5:12 AM, Klaus Major wrote:
> Hi all (and Trevor :-)
Hi Klaus :-)
> Any hints on how to popup a menu in the "Editor field" of a DataGrid?
> I want to let the user choose pre-made text to insert into that
> column, know what I mean?
This lesson shows how to trigger the data grid mousedown code before
displaying a contextual:
How Do I Show a Contextual Menu?: <http://revolution.screenstepslive.com/spaces/revolution/manuals/datagrid/lessons/2962
>
Although the example script would be placed in the data grid group
script itself you could just as easily place the code in the behavior
for a custom column template:
How Do I Customize A Table's Columns?: <http://revolution.screenstepslive.com/spaces/revolution/manuals/datagrid/lessons/3436-How-Do-I-Customize-A-Table-s-Columns-
>
> Or if that is not possible, I could also need this when right-
> clicking on any column,
> so I can insert the chosen text into the clicked column.
>
> The popup button will NOT be part of the DataGrid.
As long as the popup menu button is on the card you won't have any
problems. What you do need to do, however, is have the popup send a
message back to the custom column control so that you can update the
data grid value. I usually do this by setting a custom property on the
button before displaying it. So below you will find one way to
approach this.
-- Column behavior script
on mouseDown pMouseBtnNum
dgMouseDown pMouseBtnNum
if pMouseBtnNum is 3 then
set the uTarget of button "MyContextualMenu" to the long id
of me
popup button "MyContextualMenu"
end if
end mouseDown
Then in the menuPick handler of "MyContextualMenu" I would do
something like this:
-- button "MyContextualMenu" script
on menuPick pChosen
dispatch "UpdateColumnValue" to the uTarget of me with pChosen
end menuPick
Now you just add the UpdateColumnValue command to the column behavior
script. The code will look just like any other code in the docs that
update data grid values.
-- Column behavior script
command UpdateColumnValue pValue
put the dgIndex of the me into theIndex
put the dgDataOfIndex[theIndex] of the dgControl of me into
theDataA
put pValue into theDataA[the dgColumn of me]
set the dgDataOfIndex[theIndex] of the dgControl of me to theDataA
end UpdateColumnValue
--
Trevor DeVore
Blue Mango Learning Systems
ScreenSteps: http://www.screensteps.com
Developer Resources: http://revolution.bluemangolearning.com
More information about the use-livecode
mailing list