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?
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!