Max number of selections in listbox AppDesigner

4 Ansichten (letzte 30 Tage)
C_W
C_W am 27 Feb. 2023
Kommentiert: C_W am 1 Mär. 2023
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?

Akzeptierte Antwort

Cameron
Cameron am 27 Feb. 2023
Bearbeitet: Cameron am 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 Kommentar
C_W
C_W am 1 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by