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

2 次查看(过去 30 天)
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

采纳的回答

Jon
Jon 2022-5-31
I have attached an example of how to do what I think you are asking
  2 个评论
Jon
Jon 2022-5-31
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by