How to create Dual Listbox which copies/remove items on selection and button press?
2 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Kanishk
on 7 Aug 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.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!