how to reset drop down list(go to first option) when pushing any other button in App designer

3 ビュー (過去 30 日間)
Hikmet Osman
Hikmet Osman 2021 年 1 月 21 日
回答済み: Yvan Lengwiler 2021 年 1 月 21 日
I created dropDown list like following:
% Create ElementLisDropDown
app.ElementLisDropDown = uidropdown(app.SelectionofTargetMaterialPanel);
app.ElementLisDropDown.Items = {'Select an element', ' 1: HYDROGEN', ' 2: HELIUM', ' 3: LITHIUM', ' 4: BERYLLIUM', ' 5: BORON'} ;
app.ElementLisDropDown.ItemsData = {'1', '2', '3', '4', '5'};
app.ElementLisDropDown.ValueChangedFcn = createCallbackFcn(app, @ElementLisDropDownValueChanged, true);
app.ElementLisDropDown.Position = [20 42 151 22];
app.ElementLisDropDown.Value = '1';
In the callbacks for other button, I added the following code:
app.ElementLisDropDown.Value=app.ElementLisDropDown.Items(1);
but I'm getting this error:
Error using matlab.ui.control.internal.model.ExactlyOneSelectionStrategy/validateValuePresentInItemsData (line 236)
'Value' must be an element defined in the 'ItemsData' property.

回答 (1 件)

Yvan Lengwiler
Yvan Lengwiler 2021 年 1 月 21 日
Your ItemsData are strings
app.ElementLisDropDown.ItemsData = {'1', '2', '3', '4', '5'};
but the value you assign is an integer
app.ElementLisDropDown.Value=app.ElementLisDropDown.Items(1);
Maybe if you said this instead?
app.ElementLisDropDown.Value=app.ElementLisDropDown.Items('1');

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by