필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Maura Monville
Maura Monville 2022년 5월 31일
댓글: Jon 2022년 5월 31일
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
Jon
Jon 2022년 5월 31일
Excellent - glad that approach works for you

댓글을 달려면 로그인하십시오.

추가 답변 (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