How to Add Element/Item to Listbox in Matlab GUI (push button, listbox)
Show older comments
Hi there, I'm trying to add new (and only new) elements to my initially empty GUI Listbox, but it just doesn't work out. Here's my code for the pushbutton callback :
function pushbutton2_Callback(hObject, eventdata, handles)
Items_2 = {};
handles = guidata(hObject);
folder = handles.folder;
pathname = folder;
Item_1 = handles.selectedItemStr; %Comes from another listbox.
guidata(hObject, handles)
while ~strcmpi(Items_2, Item_1) %When the Item_1 is allready in Items_2, the While Loop ends by itself and Items_2 stays the same.
Items_2 = [Item_1, Items_2]; % However, in the contrary, Item_1 is added to the Items_2 (cell arrays of string characters)
set(handles.listbox2,'String',Items_2); %Update the list in Listbox2.
break
end
Here's my code for the listbox 2 callback :
function listbox2_Callback(hObject, eventdata, handles)
%I don't think I need to do this, but I do it anyway.
list = get(handles,'String');
set(handles,'String',list);
When I run my GUI, it shows no error, but the list doesn't update nor doesn't add any new item.
Thanks for the help!
Accepted Answer
More Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!