Max number of selections in listbox AppDesigner

9 vues (au cours des 30 derniers jours)
C_W
C_W le 27 Fév 2023
Commenté : C_W le 1 Mar 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?

Réponse acceptée

Cameron
Cameron le 27 Fév 2023
Modifié(e) : Cameron le 27 Fév 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 commentaire
C_W
C_W le 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);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by