How do I, from choosing a string from a pop-up menu, make a edit box disable?

Hi
Ive been looking for a guide to how to make a gui pop-up menu make one of my edit box disable?
Seen alot of good guides with a push button, but I need one for a pop-up menu.
Il'l try to make a image of what i need.
(Pop-up menu) | Edit 1 | | Edit 2 |
if I in pop-up menu pick option 1, I want edit box 2 to be disablet. And if i pick option 2, i want edit box 1 to be disablet.
How do I do that?
MIkkel Ibsen

 Accepted Answer

idx = get( hObject, 'Value')
switch idx
case 1: set( handles.Editbox1, 'Enable', 'off');
case 2: set( handles.Editbox2, 'Enable', 'off');
end

7 Comments

It does the first thing right, with i choose option 2, the editbox1 gets disablet, but when i go back to option 1, the editbox 1 is still disablet, and nothing has happend to editbox 2.
Im new at this gui, so please explain it in "small" words. Or just type the code.
Your question only asked for boxes to be disabled, not for the other one to be enabled ;-)
idx = get( hObject, 'Value')
switch idx
case 1: set( handles.Editbox1, 'Enable', 'off'); set( handles.Editbox2, 'Enable', 'on');
case 2: set( handles.Editbox2, 'Enable', 'off'); set( handles.Editbox1, 'Enable', 'on');
end
Yeah sorry :)
But still, dont know if I'm doing anything wrong, because its still only the editbox 1 that is disablet, nothing is happening to editbox 2. And even though I change my pop-up menu to option 2, its still editbox 1 that is disablet.
I dont know if I havent explained cleary enough what I would like. But I would like that option 1 disables editbox 2 and enables editbox 1, and option 2 disables editbox 1 and enables editbox 2.
Does that make any sence?
dx = get( hObject, 'Value')
switch idx
case 1: set( handles.Editbox1, 'Enable', 'on'); set( handles.Editbox2, 'Enable', 'off');
case 2: set( handles.Editbox2, 'Enable', 'on'); set( handles.Editbox1, 'Enable', 'off');
end
I still get an error, where do I put this code, ive placed it under the pop-up menu, but is that correct?
??? Reference to non-existent field 'Editbox1'.
Error in ==> guiproblem>popupmenu1_Callback at 86
case 1: set( handles.Editbox1, 'Enable', 'on'); set( handles.Editbox2, 'Enable', 'off');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> guiproblem at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)guiproblem('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
I cant understand why it says that Editbox1 doesnt excist. Because it does...
At the command line, command
dbstop if error
Then run your program. When it stops, examine
fieldnames(handles)
Check the names carefully. For example is it "editbox1" (with lower-case) in the handles structure ?
Instead of me trying a million things and not getting anywhere, could you make a simple gui with 1 pop-up menu and 2 edit boxes, and just make them do what I would like to do, and then send the files to mikkel-ibsen@hotmail.com
Would really really really appreciate it :)

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!