Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by