App Designer で2つのドロップダウンリストを連動したい

13 vues (au cours des 30 derniers jours)
Haruhito Kato
Haruhito Kato le 6 Oct 2022
Commenté : Haruhito Kato le 9 Oct 2022
AppDesignerで試しにアプリを作っています。あるドロップダウンリストの結果に応じてもう一つのドロップダウンリストの中身を変えたいです。可能でしょうか?

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 6 Oct 2022
Modifié(e) : Atsushi Ueno le 6 Oct 2022
可能です。具体的にはどのように連動させるのでしょうか?
2つのドロップダウンリストの項目数が同一で、同じ並びの項目になる様に連動する例を下記に示します。
下記の様に2つのドロップダウンリストのValueChangedコールバック関数を別々に定義し、「変更されていない側の項目」を、「変更された側の項目」と同じ並びになる様にインデックス番号で合わせてやれば良いのです。
properties (Access = private)
index % Description
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: DropDown2
function DropDownValueChanged1(app, event)
index = find(contains(event.Source.Items,event.Value)); % 変更された項目のインデックスを探す
app.DropDown.Value = app.DropDown.Items{index}; % 相手のドロップダウンリスト項目を合わせる
end
% Value changed function: DropDown
function DropDownValueChanged2(app, event)
index = find(contains(event.Source.Items,event.Value)); % 変更された項目のインデックスを探す
app.DropDown2.Value = app.DropDown2.Items{index}; % 相手のドロップダウンリスト項目を合わせる
end
end
または二者のコールバック関数を共通にし、どちらから呼ばれた場合でも両方の項目を設定すれば良いのです。
% Value changed function: DropDown, DropDown2
function DropDownValueChanged(app, event)
index = find(contains(event.Source.Items,event.Value)); % 変更された項目のインデックスを探す
app.DropDown.Value = app.DropDown.Items{index}; % 自分/相手のドロップダウンリスト項目を合わせる
app.DropDown2.Value = app.DropDown2.Items{index}; % 自分/相手のドロップダウンリスト項目を合わせる
end
  1 commentaire
Haruhito Kato
Haruhito Kato le 9 Oct 2022
無意識のうちに、app.DropDown.Valueは、直接書き換えられないから変更できないものかと思い込んでいました。
ありがとうございます!

Connectez-vous pour commenter.

Plus de réponses (1)

Hiro Yoshino
Hiro Yoshino le 6 Oct 2022
このあたりをみて、プロパティを変えるように設定すれば、上手く行きそうな気がしますが。試されましたか?

Catégories

En savoir plus sur App Designer を使用したアプリ開発 dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!