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

조회 수: 19 (최근 30일)
how can i reset drop down list (go to first option) when pushing any other button in App designer?

답변 (4개)

Mario Malic
Mario Malic 2021년 1월 16일
You have to add callback to every 'any other button' component that'll reset it.
app.NameOfComponentDropDown.Value = app.NameOfComponentDropDown.Items(1);

Cris LaPierre
Cris LaPierre 2021년 1월 16일
편집: Cris LaPierre 2021년 1월 16일
In the callbacks for those other buttons, add the following code.
app.DropDown.Value = app.DropDown.Items(1);

Hikmet Osman
Hikmet Osman 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
Mario Malic
Mario Malic 2021년 1월 21일
I am not super familiar with interactions between Value and ItemsData properties. You have 6 Items and 5 ItemsData values, which might confuse MATLAB.
We don't know which line in your code is 236.

댓글을 달려면 로그인하십시오.


Cris LaPierre
Cris LaPierre 2021년 1월 21일
편집: Cris LaPierre 2021년 1월 21일
You have changed your example. By default, ItemsData is empty, so the original responses set the value by indexing Items. For example, Items(1) is 'Select an element'.
From the documentation, "Notice that when the ItemsData property value is not empty, the value of the drop-down component is the ItemsData value that corresponds to the selected Items value element."
Because you've specified ItemsData, you must use those values to set the Value property, not Items. You can simplify the code in other callbacks to now be
app.ElementLisDropDown.Value='1';
What would probably make even more sense is to not define your ItemsData as text. Just use numbers.
Also be aware that you are one item short. The first ItemsData value corresponds to the first Items value. Currently, there is no ItemsData value for ' 5: BORON'
app.ElementLisDropDown.ItemsData = [1 2 3 4 5 6];
...
app.ElementLisDropDown.Value = 1;

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by