0

I am currently programming a guided user interface (GUI) in matlab which comprises a drop down menu.

When a certain element of the drop down menu is selected a second GUI is opened which contains a listbox. This listbox should now display data which have been been provided by the first GUI.

Passing the data to the second GUI works and I can update the handles variable accordingly. However I have problems to populate the listbox with the passed data because the handles in listbox1_CreateFcn(hObject, eventdata, handles) is empty:

    % --- Executes during object creation, after setting all properties.
    %function listbox1_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to listbox1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    % Hint: listbox controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.

    set(hObject,'String', handles.stringData); % THIS LINE DOES NOT WORK, 
                                               % BECAUSE handles is empty

    if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor'))
       set(hObject,'BackgroundColor','white');
    end

Do you know a solution for my problem ?

Many thanks in advance, engineer.m

dsolimano
  • 8,870
  • 3
  • 48
  • 63
  • the `listbox` is part of the "second" gui so it will not receive the guidata handles from the 1st gui unless you send them explicitly as a parameter. When you create your 2nd gui, either send the data to populate the listbox in a specific variable, or at least send a reference to the handle of the first gui (with this 1st gui handle you can retrieve the guidata of the first gui by using `guidata`, even when called from the second gui). – Hoki Apr 25 '15 at 13:50
  • I send the data from the first GUI to the second GUI explicitely via _varargin_. In the opening function of the listbox (second GUI) the contents of _varargin_ is copied into the _handles_ variable. This seems to work. – engineer.m Apr 25 '15 at 14:55
  • The `CreatFcn` executes on object creation, before your `OpeningFcn`. You should instead use `set(handles.listbox1,'string',yourStringArray);` in your OpeningFcn. – Juderb Apr 25 '15 at 16:56

0 Answers0