Drop Down Menu App Designer Values

10 ビュー (過去 30 日間)
Nick M.
Nick M. 2019 年 3 月 1 日
編集済み: Sven 2019 年 3 月 1 日
Hi, I am having an issue where the app designer GUI does not detect the default value in the drop down menu to hide something specific. For example, if the default value in the drop down menu is Option 1, the field is not hidden unless I select another Option such as Option 2 and reclick Option 1. Is there a way for app designer to detect the default drop down menu value at launch to hide something? Below is the code I wrote so far.
function DropDownValueChanged(app, event)
value = app.DropDown.Value;
if strcmp(value,'Option 1')
app.MassofobjectEditField.Visible= 'off';
else
app.MassofobjectEditField.Visible= 'on';
end
end

採用された回答

Sven
Sven 2019 年 3 月 1 日
編集済み: Sven 2019 年 3 月 1 日
The code won't execute because, it is a ValueChanged function which means it has to detect a change in its value to do something. This is not the case if you start it with Option 1 and want to do something when Option 1 is selected. You first have to change to another value and then back to Option 1.
If you want MassofobjectEditField to be hidden upon starting your app, you can call
app.DropDownValueChanged(app, [])
inside your startup function after the DropDown Menu is created. (See the comment below.) The startup function executes after starting your app and can be added by clicking the green plus and choosing the StartupFcn callback.
  2 件のコメント
Guillaume
Guillaume 2019 年 3 月 1 日
I would not recommend doing this exactly, since you now have two different locations to edit if you ever change the logic of the code. Rather, I'd recommend firing off the event yourself at the end of the start up function. Then all the logic is contained in the callback.
So somewhere in the startup function, after the dropdown value has been set,
app.DropDownValueChanged(app, [])
to force the callback to execute.
Sven
Sven 2019 年 3 月 1 日
You are right. This way it's much better. Didn't think about that, thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by