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

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Develop 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