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

1 vue (au cours des 30 derniers jours)
Maura Monville
Maura Monville le 31 Mai 2022
Commenté : Jon le 31 Mai 2022
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

Réponse acceptée

Jon
Jon le 31 Mai 2022
I have attached an example of how to do what I think you are asking
  2 commentaires
Jon
Jon le 31 Mai 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
Jon
Jon le 31 Mai 2022
Excellent - glad that approach works for you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by