Clear Filters
Clear Filters

Max number of selections in listbox AppDesigner

5 views (last 30 days)
I'm working on migrating a GUIDE app to an AppDesigner app.
In the GUIDE app, a listbox is filled with a number of elements to be selected from. Multiple items can be selected, but only between 1 and 10 listbox items should be able to selected.
GUIDE code example:
set(handles.listbox,'String',listbox_elements); % in AppDesigner: set(app.handles.listbox, 'Items', listbox_elements)
set(handles.listbox,'Min',1,'Max',10);
set(handles.listbox,'Value',1);
Is there currently an analogous way to set the maximum amount of multi-selected Items in an AppDesigner listbox?

Accepted Answer

Cameron
Cameron on 27 Feb 2023
Edited: Cameron on 27 Feb 2023
value = app.ListBox.Value;
N = 10; %max number of selections
if length(value) > N
app.ListBox.Value = app.ListBox.Value(end-N:end);
end
  1 Comment
C_W
C_W on 1 Mar 2023
Thanks Cameron,
This worked great, except I need to edit the line within the if statement, to add N+1.
app.ListBox.Value = app.ListBox.Value(end-N+1:end);

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!