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

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Kanishk
Kanishk il 7 Ago 2024
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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by