MATLAB: Ho to make a popup box enable/disable visibility of textbox

guigui interfaceMATLAB

Hi guys!
I'm building a GUI interface and i want to disable and enable the visibility of a textbox (entry user information box), from popup list. How cand i do that?
My popup has 4 differents options, the first 2 options i want enable and for 3 an 4 option disable.
One more thing, i already saw some structures on web, but it doesn't seem to work form, but i suspect that i'm using it in the wrong place of my script, where should i write this commands?
Cheers!

Best Answer

You need to add a callback that checks for the value of your dropdown menu and edits the enable value of your edit textbox. As we do not know the structure of your code here is a small example how you would approach it:
function exampleGui
handles = struct;
hFig = figure;
handles.dropdown= uicontrol('Parent', hFig,...
'Style','popupmenu',...
'String',{'Can edit 1', 'Can edit 2', 'Cannot edit 1', 'Cannot edit 2'},...
'Units','normalized',...
'Callback', @onEditDropdown,...
'Position',[0.1 0.4 0.2 0.2]);
handles.textbox = uicontrol('Parent', hFig,...
'Style','edit',...
'Units','normalized',...
'Position',[0.4 0.4 0.5 0.2]);
function onEditDropdown(src,event)
if src.Value>2
handles.textbox.Enable = 'off';
else
handles.textbox.Enable = 'on';
end
end
end