Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
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.

Antworten (1)

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

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by