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

6 views (last 30 days)
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.

Answers (1)

Yvan Lengwiler
Yvan Lengwiler on 21 Jan 2021
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');

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!