ContextMenuOpeningFcn event data not containing the correct right-clicked item (a Matlab bug?)

2 views (last 30 days)
I'm using a context menu in App Designer that should open and display different options based on the item clicked within a listbox.
I was happy to find out that in Matlab 2023b, ContextMenuOpeningFcn callback has additional event data when the callback is associated with a context menu on a UI component:
ContextObject - Object that the app user right-clicked to open the context menu
InteractionInformation - Information about where in the component the app user right-clicked to open the context menu, such as the cell of a table.
However, when assigning the context menu to a ListBox, the 'InteractionInformation' property contains only an 'Item' field which matched the selected item in the listbox. To be clear - the selected item is not necessarility the right-clicked item.
I think this is a bug in the event data behavior - the most logical 'InteractionInformation.Item' value would be to point at the index of the right-clicked item.
Any suggestions for a way around it?

Answers (1)

Yatharth
Yatharth on 7 Dec 2023
Hi Zachi!
I understand that you want l 'InteractionInformation.Item' value to point at the index of the right-clicked item in the ListBox and not the Item selcted.
As per the MATLAB documentation, your expected behavior is precisely as described.
I tried reproducing the issue at my end. As you can see the Item selected is 2 but I clicked on Item 4 and it showed the correct Item Number
Here is the code for the same, Make sure you are using R2023b
function ContextMenuOpening(app, event)
disp(event.InteractionInformation)
data = event.InteractionInformation;
app.TextArea.Value = string(data.Item);
end
I hope this helps!
  1 Comment
Zachi
Zachi on 10 Dec 2023
Edited: Zachi on 10 Dec 2023
Thank you,
I have validated your solution to work in a similar simple example, however it is not working in my case.
I have found the differentiating factor - if the Item text is html then the event.InteractionInformation.Item value will be the index of the selected item and not the right-clicked one.
Unfortunately, in my case I need to apply different styling within each item so I can't replace the html text with plain text :(
I also tried to assign plain text to the items and them it works like a charm.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!