How to use context menu for app designer

Hi,
I'm fiding it really difficult figuring out how the conetext menu works in app designer.
I have 4 listboxes that i have linked to a context menu.
I when i use the conext menu that has a "delete" item that I've created. I want the callback to know which listbox has icicated the contextmenu callback.
Tried to read the documentation but didn't seem to be able to get it working

Answers (2)

Each listbox has its own contextmenu, right? You should be able to tell which listbox is calling, right?
Attach a screenshot if this is not the case.

5 Comments

No I have 4 separate list boxes linked to a one context menu. I was hoping that I could pass a handle of the listbox that that called the context menu instead of having 4 separate implementations as the context menu should do the same operation to the list box selected.
I see. Theoretically you can assign different context menus to different listbox, or you can share the same context menu among all listboxes.
If the callback depends on which listbox, maybe it is easier to assign one (different) context menu for different listbox?
Fair enough, thanks for the answer I'll try it the way you suggested.
I was just hoping there was a way to pass a handle/indetifier or Tag to help reduce the overal complexity of the app.
Maybe a possible feature to add to a future release?
I had to go with the following solution below which just seems foolish to me.
Lee
Lee on 2 Aug 2022
Edited: Lee on 3 Aug 2022
I agree with you, Paul. This is idiotic, and a massive limitation of AppDesigner compared to GUIDE. Similarly, the ONLY callback available for Listboxes is ValueChanged, making it impossible to change any properties of the app after clicking inside a listbox for example (which would solve your problem). Instead we are forced to duplicate context menus, callbacks, and buttons because now they have to be dedicated to each and every listbox - thanks Mathworks!

Sign in to comment.

Raph
Raph on 29 Nov 2023
Edited: Raph on 29 Nov 2023
There is an easy work around that I use for dynamically built interfaces that you may use here.
  • Simply assign the target component as the UserData of the uimenu component.
function pop(src,event)
if strcmp(src.Checked,'on')
src.Checked = 'off';
src.UserData.Items = {'Bonjour','Bonsoir'};
else
src.Checked = 'on';
src.UserData.Items = {'Good Morning','Good Night'};
end
end
cm = uicontextmenu(app.UIFigure);
m = uimenu(cm,'Text','English','Checked','on','UserData',app.ListBox);
app.ListBox.ContextMenu = cm;
  • Assign the MenuSelectedFcn callback to your custom function
m.MenuSelectedFcn = @pop;
  • Then, whenever you check the box of the context menu, it will go to the function and change the data of the listbox by assigning new values to the items which are accessible through the src.UserData which is a pointer to the desired target object.
Hope Lee's anger is solved with this answer.

1 Comment

Not really, given that I was having the issue over a year ago, and have since changed company.. Nevertheless, I appreciate your effort!

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Asked:

on 25 Nov 2021

Commented:

Lee
on 29 Nov 2023

Community Treasure Hunt

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

Start Hunting!