MATLAB: Changing one popup values from another popup menu with guide

guiguide

Hello everybody,
I've stumbled with a guide related problem. and would appreciate your help.
I have several option in one popup menu each of those corresponds to different set of options. to be chosen in the second popup menu
I want to choose from the first popup menu and immediately change the values corresponding to this field.
As for now the values in the second popupmeanu change only * when I pressed it twice,* meaning invoke it. so it works but not the way I wanted to. Is there any way to update and implement this change immediately when the user pick the values from the first popup menu?
I've attach the code responsible for this change:
function popupmenu1_Callback(hObject, eventdata, handles)
items = get(hObject,'String');
index_selected = get(hObject,'Value');
handles.DataBlock= items(index_selected,:);
handles.DataBlock
switch handles.DataBlock{:}
case 'B111'
list={'Time';'Version' ; ...}
case 'B116'
list={'Time'; 'Version'; 'Sub_frame_Number'; 'System_FN'}
case 'B123'
..
..
end
handles.current_list
handles.current_list=list;
guidata(hObject,handles)
function popupmenu2_Callback(hObject, eventdata, handles)
set(hObject,'String', handles.current_list );
guidata(hObject,handles);
Thank you for the help,
Elad

Best Answer

Why wait until the user interacts with popup2 to set the items in it? That's your problem. Set the items in popup2 immediately as soon as you know them in the popup1 callback. You can set the values/properties of any other controls in any callback since you have the handles of everything. So in popupmenu1_Callback(), after you determine "list", do this
handles.popupmenu1.String = list; % Preferred/recommended way
Or, if you have an antique version of MATLAB, use set():
set(handles.popupmenu1, 'String', list); % Ancient way
Obviously you'd then also take out any code for setting the items in the popupmenu2 callback.