App Designer ListBox ValueChanged Callback with multiselect 'on'

14 ビュー (過去 30 日間)
Suchitha Nama
Suchitha Nama 2022 年 4 月 6 日
コメント済み: Suchitha Nama 2022 年 4 月 7 日
I have 2 listboxes, one with a list of test number and another that is a list of run numbers. If I select a test number from the list box, I have a callback , TestListBoxValueChanged(app, event), that will display the corresponding run number for that specific test in the "Run" List box. This is working great when I only select one test, but I have multiselect on and when I try to select 2 or more tests, not all the run numbers show in the run listbox. I am using ctrl + click, or shift + click to select multiple test items from the list and I only see run numbers for the first clicked item.
I need help figuring out why the TestListBoxValueChanged callback is not working with multiple selections. Does the callback get triggered when multiple items are selected, including the original singly selected item?
function TestListBoxValueChanged(app, event)
% Get test numbers to index into dataset, convert to double.
selectedTest = str2double(app.TestListBox.Value);
selectedButton = app.TestDataSetButtonGroup.SelectedObject.Text;
if strcmp(selectedButton, "correctString")
datastruct = app.someData;
else
datastruct = app.otherData;
end
% Use array of double to index into data struct and get all of
% the runs for the test(s) selected.
runs = datastruct(selectedTest).runNumber;
% Update RunListBox
app.RunListBox.Items = string(runs);
end

採用された回答

Voss
Voss 2022 年 4 月 6 日
Try this (note the square brackets [ ]):
% Use array of double to index into data struct and get all of
% the runs for the test(s) selected.
runs = [datastruct(selectedTest).runNumber];
More information:
  2 件のコメント
Suchitha Nama
Suchitha Nama 2022 年 4 月 7 日
I tried this, and it works when I have selected 2 items, but when I try and select 3 items from the test list box, the run list box does not get updated. Also I have noticed that after a few times of selecting, the initial problem persists and only runs from the first selected test show again. Might this be an issue with the callback being triggered before the previous callback has been processed?
Suchitha Nama
Suchitha Nama 2022 年 4 月 7 日
I think I figured it out. Along with what you mentioned above, I added code to clear/delete Items from the RunListBox and now I am seeing all of the correct runs.
% Value changed function: ProbeListBox
function ProbeListBoxValueChanged(app, event)
% Delete Items in RunListBox
app.RunListBox.Items = {};
% Get probe numbers to index into dataset
...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by