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

1 次查看(过去 30 天)
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?

回答(1 个)

Yatharth
Yatharth 2023-12-7
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 个评论
Zachi
Zachi 2023-12-10
编辑:Zachi 2023-12-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by