Controlling a ListBox's items from a PopupMenu

1 次查看(过去 30 天)
Hi,
I have a popup menu that changes a global variable in its callback, and the global variable is used as an index for several things to keep track of where I'm at in my data structure.
I also have a Listbox. What I want to do is, whenever I select something from the popupmenu, the listbox should update its selections according to what the value picked in the popup menu (the global index) is.
Is there a way to force the list to update whenever the popup updates?

回答(1 个)

Ben11
Ben11 2014-7-14
Yes. In the popup menu callback you can edit what appears in the Listbox using its handles and "string" property. The simpler would be to pre-define elements you want to display depending on the selection in the popup menu and then assign them as the "string" property of the Listbox.
Simple example (popupmenu callback):
switch(get(hObject,'Value')) % get current value selected in popup menu. I'm assuming numbers but it can be strings or else.
case 1
set(handles.Listbox,'String',StringArray1);
case 2
set(handles.Listbox,'String',StringArray2);
etc.
end

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by