How to create Dual Listbox which copies/remove items on selection and button press?

조회 수: 2 (최근 30일)
Hi, here below we have my two beautiful independant listboxes.
The first listbox contains all the items while the second listbox should only store those I choose.
For that, I need to copy the items from Listbox 1 to Listbox 2, then call those copied items in some other function (I'm trying to be general here).
For example, Listbox 1 has A, B, C, D and E and I would like Listbox to display A, D and E when I select the items (can be 1 at a time or multiple at once, whatever is feasible).
My obvious question is : How would I do that?
PLPL.png

답변 (1개)

Kanishk
Kanishk 2024년 8월 7일
Hi Thomas,
I understand that you need to transfer Items from one List to another list with some interaction.
You can achieve this functionality by creating a Callback function and attach it to the first Listbox’s ValueChangedFcn.
function allItemCallback(app, src, event)
if ~ismember(event.Value, app.selectedItems)
app.selectedItems{end+1} = event.Value;
end
app.SelectedItemsListBox.Items = app.selectedItems;
end
You can add this callback function to the ValueChangedFcn of the List Box.
app.AllItemsListBox.ValueChangedFcn = @app.allItemCallback;
The Callback will add Items from All Items List Box to Selected Items List Box uniquely when selected.
To learn more about ` uilistbox` and its Callback functions you can follow this link: https://www.mathworks.com/help/releases/R2024a/matlab/ref/uilistbox.html#bui0qid
You can also create a similar Callback on Selected Items List Box to remove Item when Selected or on pressing a Button.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by