Max number of selections in listbox AppDesigner

5 visualizaciones (últimos 30 días)
C_W
C_W el 27 de Feb. de 2023
Comentada: C_W el 1 de Mzo. de 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?

Respuesta aceptada

Cameron
Cameron el 27 de Feb. de 2023
Editada: Cameron el 27 de Feb. de 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 comentario
C_W
C_W el 1 de Mzo. de 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);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by