MATLAB Answers

Select all items of a list box within app designer

50 views (last 30 days)
Justus Boehm
Justus Boehm on 23 Mar 2020 at 6:40
Answered: Justus Boehm on 3 Apr 2020 at 5:34
Hello together,
I have a rather simple problem and I am wondering whether it´s my or Matlab´s fault.
In an app, created with App Designer, I have a list box with 1000+ entries. I want to create a button, that selects all items in the list box, when pushed.
I figured, the easiest way is to simply get all items in the list box and then pass it to the app.ListBox.Value variable (code below)
It definitely works, but it is really slow. Reading the items is not the problem:
Read items from the list box: 0.000263 s
Write items to the Value variable: 5.6392 s
If I click on the first item, scroll all the way down to the last, press Ctrl+Shift and click the last item, all items are selected instantly. So there must be a way to do this without waiting for 5 or more seconds...
Does anybody have a better solution or can tell me, what I am doing wrong?
Best regards,
Justus
% Button pushed function: SelectAllButton
function SelectAllButtonPushed(app, event)
% Start timer
tic
% read all items from the list box
Items = app.ListBox.Items;
% stop the timer and write the time to a variable
ReadItemsTime = toc;
% start a second timer
tic
% Select all Itmes, by passing the cell array to the Value
% variable
app.ListBox.Value = Items;
% stop the second timer
WriteValueTime = toc;
% display the times
disp(['Read items from the list box: ' num2str(ReadItemsTime) ' s'])
disp(['Write items to the Value variable: ' num2str(WriteValueTime) 's'])
end

  3 Comments

Ajay Kumar
Ajay Kumar on 23 Mar 2020 at 8:52
why don't you use check box instead of listbox?
Justus Boehm
Justus Boehm on 23 Mar 2020 at 8:58
Because i have a variable count of elements in the listbox and i dont want to create a checkbox for every element every time the app reloads data.
Mohammad Sami
Mohammad Sami on 23 Mar 2020 at 9:21
This looks like an issue with how Matlab internally implemented the setting of values. I think it can be sped up. Perhaps you can raise a support ticket to highlight this performance issue.

Sign in to comment.

Accepted Answer

Justus Boehm
Justus Boehm on 3 Apr 2020 at 5:34
For everyone who is interested:
I opened a support ticket and learned, that the development team is aware of this performance issue with large multi-select ListBox.
Numeric values in ItemsData (instead of Items), should be slightly faster (~20% faster) than using Items if this is a high frequency workflow.
app = struct;
app.ListBox = uilistbox('Items', "Items" + (1:1000));
app.ListBox.Multiselect = 'on';
app.ListBox.ItemsData = 1:1000;
% Start timer
tic
% read all items from the list box
ItemsData = app.ListBox.ItemsData; % USE ItemsData instead of Items
% stop the timer and write the time to a variable
ReadItemsTime = toc;
% start a second timer
tic
% Select all Itmes, by passing the cell array to the Value
% variable
app.ListBox.Value = ItemsData;
% stop the second timer
WriteValueTime = toc;
% display the times
disp(['Read items from the list box: ' num2str(ReadItemsTime) ' s'])
disp(['Write items to the Value variable: ' num2str(WriteValueTime) 's'])

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019b