Max number of selections in listbox AppDesigner

9 次查看(过去 30 天)
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?

采纳的回答

Cameron
Cameron 2023-2-27
编辑:Cameron 2023-2-27
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 个评论
C_W
C_W 2023-3-1
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by