ContextMenuOpeningFcn event data not containing the correct right-clicked item (a Matlab bug?)
2 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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.
You can find the specific section in the documentation by following this link. https://www.mathworks.com/help/matlab/ref/uicontextmenu.html?searchHighlight=InteractionInformation&s_tid=srchtitle_support_results_10_InteractionInformation#:~:text=Index%20of%20the%20right%2Dclicked%20list%20box%20item%2C%20returned%20as%20a%20numeric%20scalar.
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!
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!