I need to populate ListBox_2 when an item in ListBox_1 is selected

1 view (last 30 days)
I have 4 ListBoxes in my GUI created through App Designer.
I need to populate Listbox_2 according to which item in ListBox_1 has been selected.
Basically I need an event "Item_Selected" ad relative callback that does not seem to ba available for the ListBox.
The only cllback available is "ValueChanged". Is such an event triggered when an item is selected?
How can I generate such an evet myself?
Thank you very much

Accepted Answer

Jon
Jon on 31 May 2022
I have attached an example of how to do what I think you are asking
  2 Comments
Jon
Jon on 31 May 2022
Basically you provide a Value Changed callback function for the first list. In this function you look at the selection, e.g. app.ListBoxA.Value, and define the Items property of the second list based on this choice.
% Value changed function: ListBoxA
function ListBoxAValueChanged(app, event)
value = app.ListBoxA.Value;
% Build second drop down based on selection in first drop down
switch value
case 'Vegetable'
app.ListBoxB.Items = {'carrots','peas','brocolli'};
case 'Grain'
app.ListBoxB.Items = {'wheat','millet','barley'};
case 'Cheese'
app.ListBoxB.Items = {'camembert','cheddar','brie'};
end

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!