How can I programmatically select multiple choices from a uilistbox?

I have an App Designer app containing a uilistbox that has both the 'Items' and 'ItemsData' properties specifed.
When my users close the app, I use setpref() to keep a persistent record of which values were selected in the uilistbox.
% Save user preferences
setpref('dddPrefs', 'ReportHeaderFields', app.ReportHeaderListBox.Value);
in the startupFcn method of the app, I use getpref() to grab the values that were previously selected in the uilistbox. The preferences aspect works fine. I can display the selected values in a message box, for example.
However, when I try to use the persistent preference value to reselect the appropriate items from the ullistbox, I cannot select more than one programatically. If I only select one value from the uilistbox and restart the program, that same value is indeed selected when I reopen. However, if I select multiple options and restart the program, the uilistbox appears to have no items selected.
% Read in preferences
app.ReportHeaderListBox.Value = getpref('dddPrefs', 'ReportHeaderFields');

3 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 5 月 15 日
Joseph - when you select more than one item in your list box and save that to your preferences, what is the value of
getpref('dddPrefs', 'ReportHeaderFields')
when you assign it to the value property of the list box? Is it a cell array? Does it have all of the items that you have selected?
Joseph Pawlowski
Joseph Pawlowski 2019 年 5 月 15 日
Geoff,
I ran my app and selected manually from the GUI five items within the uilistbox. I then closed my app and in the command window, I ran the following command, which gives me a 1x5 cell array.
getpref.PNG
Monika Jaskolka
Monika Jaskolka 2020 年 10 月 7 日
編集済み: Monika Jaskolka 2020 年 10 月 7 日
Just wanted to say that I also have this issue. It tried the following code to incrementally select the items one-by-one, and it doesn't work. If I add a breakpoint and step through the code, it works just fine. Also, if I attempt to multi-select programmatically (which doesn't select anything), it then prevents me from subsequently multi-selecting via the GUI (shift+select).
for i = 1:length(perferenceVal)
app.ListBox.Value{end+1} = perferenceVal{i};
drawnow;
end

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

 採用された回答

Joseph Pawlowski
Joseph Pawlowski 2020 年 1 月 2 日

0 投票

It looks like whatever this issue was, it is no longer an issue in R2019b.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by