how to set the value of popup menu in another callback?
10 次查看(过去 30 天)
显示 更早的评论
I want the popup menu string to change to the original whenever I change another field's string value in the GUI. could anyone help out?
thanks
0 个评论
回答(2 个)
Walter Roberson
2013-2-15
set(handles.popupmenu, 'Value', 1)
where popupmenu is replaced by the tag of the pop up menu.
0 个评论
Sean de Wolski
2013-2-15
编辑:Sean de Wolski
2013-2-15
Use addlistener to listen to 'PostSet' events of the string changing in other uicontrols.
function showStringUpdate
%Figure
hFig = figure;
%Listbox
hList = uicontrol('Style','listbox',...
'Units','normalized',...
'Position',[0.5 0.1 0.3 0.5],...
'String',{'Hello World','It''s Friday','And a Three day Weekend!'},...
'Max',1,... %Increase for multiselect
'Value',1,...
'Callback',[]);
%Editboxes
for ii = 3:-1:1
h(ii) = uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.1 0.1*ii 0.3 0.1],...
'String','Type in Me',...
'Callback',[]);
addlistener(h(ii),'String','PostSet',@(src,evt)set(hList,'Value',1));
end
end
Save this, move the listbox selection to something else, and then type in any box.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!