How to create Dual Listbox which copies/remove items on selection and button press?
5 ビュー (過去 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 で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!