Controlling a ListBox's items from a PopupMenu
이전 댓글 표시
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
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
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!