0

From my "Main" window I have a button that opens another window "List". In the List window I have two listboxes the one on the left has names on it and on the one on the right i add names to it. However I am unable to pass the added names to the list to the "Main" window once I click the ''OK" button on the "List" window.

function Done_Button_Callback(hObject, eventdata, handles)

    SelectedFaults = get(handles.SelectedFaults_Listbox,'String');  
    set(Main, handle.Faults_Listbox,'String',SelectedFaults)   
    close(Insert_Fault)

the error that I'm getting is:

 ??? No appropriate method, property, or field Faults_Listbox for class handle.

Error in ==> Insert_Fault>Done_Button_Callback at 380

set(Main, handle.Faults_Listbox,'String',SelectedFaults)

Error in ==> gui_mainfcn at 96
    feval(varargin{:});
  Error in ==> Insert_Fault at 42

gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback

both m files are in the same directory. I'm stuck. thank you for your help

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
VMI
  • 61
  • 10

1 Answers1

1

Your code does not show how the variable "handle" is defined. Did you mean "handles"? In this case, the handles structure is the one that comes with the Insert_Fault figure, and has nothing to do with the handles structure of the Main figure.

If you want to modify the listbox in the Main window, you could pass the handle of the Faults_Listbox from the Main figure to the Insert_Fault figure, for example via userdata or appdata.

The following code should do what you want.

In Main:

% Callback of a button in main that opens the Insert_Fault figure
function Open_Insert_Fault_Callback(hObject, eventdata, handles)
Insert_Fault('UserData', struct('Mainhandles', handles));

in Insert_Fault:

function Done_Button_Callback(hObject, eventdata, handles)
SelectedFaults = get(handles.SelectedFaults_Listbox,'String');  

userdata=get(handles.figure1, 'UserData');
Mainhandles=userdata.mainhandles;

set(Mainhandles.Faults_Listbox,'String',SelectedFaults)   
close(Insert_Fault)
mars
  • 774
  • 1
  • 13
  • 17
  • fantastic... with a little tweaking your code worked. Thank you very much for your help – VMI Jun 08 '12 at 16:13