필터 지우기
필터 지우기

Moving selected entry from a listbox to another listbox and adding more to the list

조회 수: 2 (최근 30일)
Hi,
I'm trying to move one entry at a time from a listbox (channelList) to another listbox (importList). I can't figure out how to get it to add multiple entries without overwriting the previous entry. I select a choice on my first listbox, channelList, hit my pushbutton that will move it to the other listbox, importList, it works. I get the correct entry in importList. However, if I need to add another entry to importList, I select one from the first listbox, channelList, hit my move to importList pushbutton, and it will just overwrite the first entry. I don't know how to get around this and make the second list box actually be a list and not just a single entry.
Here is my pushbutton code:
entries = cellstr(get(handles.channelList,'String'))
selected = entries{get(handles.channelList,'Value')}
set(handles.importList,'String', selected)
Thanks ahead of time.
Edit: I tried to use an array with an index but for some reason it still just erases the previous entry...
entries = cellstr(get(handles.channelList,'String'));
selected = entries{get(handles.channelList,'Value')};
selectedList(handles.index) = [{selected}]
handles.index = handles.index + 1
guidata(hObject,handles)
set(handles.importList,'String', selectedList);

채택된 답변

Anthony
Anthony 2015년 6월 17일
I got it to work.
function importGUI_OpeningFcn(hObject, eventdata, handles, varargin)
%
handles.index = 1;
guidata(hObject,handles)
%
function addSelected_Callback(hObject, eventdata, handles)
%
entries = cellstr(get(handles.channelList,'String'));
selected = entries{get(handles.channelList,'Value')};
handles.selectedList(handles.index) = [{selected}]
handles.index = handles.index + 1
guidata(hObject,handles)
set(handles.importList,'String', handles.selectedList);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by