App Designer で2つのドロップダウンリストを連動したい
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Haruhito Kato
le 6 Oct 2022
Commenté : Haruhito Kato
le 9 Oct 2022
AppDesignerで試しにアプリを作っています。あるドロップダウンリストの結果に応じてもう一つのドロップダウンリストの中身を変えたいです。可能でしょうか?
0 commentaires
Réponse acceptée
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
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur App Designer を使用したアプリ開発 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!