user2262401
user2262401

Reputation: 1

matlab gui popup menu error message

I have created a GUI and there is a pop-up menu in it. I want to know how I can generate an error dialogue when the pop-up menu is not open/used by a user. For the edit box, I use "isempty", but that doesn't work for the pop-up menu. if the user don't open the pop-up menu and don't select any choice from this pop-up menu i want my program display an error message for remind the user select a choice.

Thanks and I look forward to hearing your solution

Upvotes: 0

Views: 2030

Answers (1)

Eugenio
Eugenio

Reputation: 276

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    val=get(handles.popupmenu1,'Value');
        switch val
                case 1, errordlg('invalid option');
                case 2, disp('option 1 selected'); %SEE COMMAND WINDOW
                case 3, disp('option 2 selected'); %SEE COMMAND WINDOW
        end

(to be clearer) set the first string of the popup menu to something like "choose an option"; that string has value 1 and is displayed in the popup when you start the gui. if the user do not change the selection of the popup or re-selects it, the error occurs.

Upvotes: 1

Related Questions