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

조회 수: 2 (최근 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