Controlling a ListBox's items from a PopupMenu

2 vues (au cours des 30 derniers jours)
Hal
Hal le 14 Juil 2014
Réponse apportée : Ben11 le 14 Juil 2014
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?

Réponses (1)

Ben11
Ben11 le 14 Juil 2014
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

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by