필터 지우기
필터 지우기

How to delete a component in a listbox?

조회 수: 7 (최근 30일)
Jihad Chamseddine
Jihad Chamseddine 2014년 7월 14일
댓글: Marcel Maeder 2018년 12월 13일
hi I used the below code for adding components for a listbox and it finally works but know I want to know if I want to delete a component from the listbox what should I do please? hope you can help me guys
this is the code that I have used
prompt=('please enter the component name: '); name=('input component name'); numlines=1; defaultanswer={''};
% prompt the user for some input answer = inputdlg(prompt,name,numlines,defaultanswer,'on'); % get the current list box selections selections = get(handles.listbox1,'String'); % append the answer to the list selections = [selections ; answer]; % update the list box with the new selection set(handles.listbox1,'String',selections);

채택된 답변

Ben11
Ben11 2014년 7월 14일
편집: Ben11 2014년 7월 14일
You do pretty much the same thing as before, i.e. modify the string array and put it back in the listbox with the set(...) command.
Let's say your string looks like this:
selections = {'A' 'B' 'C'};
Then you delete say the 2nd element:
selections(2) = []
selections =
'A' 'C'
And you can put it back in the listbox:
set(handles.listbox1,'String',selections);
  댓글 수: 7
Nam Hoang Le
Nam Hoang Le 2017년 2월 16일
Do you know how to solve this? I also had this problem
Marcel Maeder
Marcel Maeder 2018년 12월 13일
You need to set your listbox value back to '1' so that the first can be selected (the listbox is made invisible since it is trying to select a number in the list that no longer exists).
set(handles.listbox,'Value',1);

댓글을 달려면 로그인하십시오.

추가 답변 (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