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

6 vues (au cours des 30 derniers jours)
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.

Réponses (1)

Yvan Lengwiler
Yvan Lengwiler le 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');

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by