Multiple choices in a listbox

조회 수: 7 (최근 30일)
Nuno Fernandes
Nuno Fernandes 2011년 5월 31일
I want to select multiple elements of a listbox and show them in another one. How can i do this in a simple way?
thanks

채택된 답변

Matt Fig
Matt Fig 2011년 5월 31일
If you set 'min' to 0 and 'max' to 10, you will be able to select multiple strings. Once you have that you can get the choices by:
C = get(U,{'string','value'})
C = C{1}(C{2})
Then set the 'string' property of the other listbox to C.
  댓글 수: 2
Nuno Fernandes
Nuno Fernandes 2011년 5월 31일
I already knew that part of 'set '...min' to 0 and 'max' to 10...'. Now i can't save the selected elements to a matrix and then show them on other listbox...
Matt Fig
Matt Fig 2011년 6월 1일
Interesting, it seems to work for me...
U = uicontrol('style','listbox',...
'units','pix',...
'string',{'Poodle';'stubb';'false';'together';'spanish'},...
'pos',[10 10 50 100],...
'min',0,'max',10,...
'callback',['C = get(gcbo,{''string'',''value''});',...
'set(U(2),''string'',C{1}(C{2}))'])
U(2) = uicontrol('style','listbox',...
'units','pix',...
'string','',...
'pos',[80 10 50 100],'min',0,'max',10)

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 5월 31일
Set the 'Max' property of the listbox to be at least 2 greater than the 'Min' property. You will then be able to select multiple items in the usual ways (e.g., click-and-drag or control-click or as appropriate for your OS.) The listbox Value property will return an array of the indices of all the currently selected entries.
Note: the Callback will be called every time the selection changes, so if you are adding entries one by one using control or alt, then multiple callbacks will be generated.
  댓글 수: 3
Matt Fig
Matt Fig 2011년 6월 1일
See the example I show above...
P
P 2012년 9월 5일
Have you tried using the 'handles' structure to save the data in the callback of the first listbox and then displaying using a callback for the second listbox?

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by