Finding the selected index in the Contextual menu?

I have read the whole page in the Documentation about the Desktopmenuitem, but cannot figure out how to determine which item was chosen by the user from a Contextual Menu. Knowing this, I can run a specific code.

I tried:
if DesktopMenuItem = “Create New Location from Selection” then
MessageBox(txt + (" has been added to the Location list.")
Return True
End If

select case hitItem.Text
case “Create New Location from Selection”
MessageBox(txt + " has been added to the Location list.")
return true
end select

In the ConstructContextualMenu Handler, I have this code:
base.AddMenu(new MenuItem(“Create New Character from Selection”))
base.AddMenu(new MenuItem(“Create New Location from Selection”))

The Event name to implement is

Yes, that is what I saw in a video about it, but that Event Handler is not available, it doesn’t seem to exist anymore in the latest Xojo version. I checked a couple of Objects to see if it’s maybe a factor and it showed 1 time in a Canvas object, but not anymore on other Canvas objects. It doesn’t show up in any other object at all.

Yes it exists, so it’s unclear what you are doing wrong. Here’s one of my subclasses using it.

Screenshot 2022-08-10 at 08.49.02

When you get the context menu “Add to myControl” and you select “Event handler …”, you get a panel showing the events you can add and you select one. Perhaps you are not scrolling that panel to see ALL the events there are in it.

This is with Xojo 2022r2.

This is what I see:

What Xojo version are you using?

ContextualMenuAction. Looks like a Desktop 1.0 ListBox.

2022 version2

Isnt it ContextualMenuAction you need from that list?

Is your object a DesktopListbox ?

No, it’s a Text Area.

Are you sure that’s the screenshot you took? TextArea shouldn’t have Cell* or Header* events, and your object is apparently named “ListBoxCharacters”.

and their names does not starts using “ListBox” either…

I seeked the documentation, then I shared the link and Event name. I do not fired Xojo 22r2 (not enough memory to do that: Firefox, Xojo 21r2.1, and some others are running)…

If you are trying to implement this on a TextArea, the answer is the same as what I gave above. You need to implement the ContextualMenuAction event.

ah sorry, you are right. Here is the correct screenshot:

Screenshot 2022-08-10 at 10.20.18

So, not a DesktopTextarea, then.

Either you’ve already implemented the ContextualMenuAction or ContextualMenuItemSelected event, or you’re subclassing something else that doesn’t expose it. In the navigator on the left of your screen, click the arrow beside “TextWritingAreaStep1” to expand the item and see if either of those is present.

1 Like

I fired Xojo 22r2 and get a screen shot:

It is clear: you have both Contextual Events you need.

Check what Anthony wrote above, please.

Just to skip ahead so you have the information, once you have added that EventHandler, the MenuItem that was selected will be in the hitItem parameter. You can access its index, text, and other information using that variable name.

Yes, I already use the ContextualMenuAction Event, but my problem is now that I don’t know the correct syntax how to get a selected menu item detected. For example, I want to write code for when the 2nd item is chosen from the menu, how do I do this? Right now it doesn’t matter if I choose the 1st or 2nd item, both are giving the same MessageBox response.