ListBox MultiSelect simulate always with Ctrl modifier?

4 visualizaciones (últimos 30 días)
Jonas
Jonas el 13 de Feb. de 2023
Editada: Jonas el 16 de Feb. de 2023
dear community,
can someone check the ListBox MultiSelect Example from the documentation for me? It does not work for me, I can only select one item, not multiple at once
function multiselect
fig = uifigure('Position',[100 100 350 275]);
% Create Text Area
txt = uitextarea(fig,...
'Position',[125 80 100 50]);
% Create List Box
lbox = uilistbox(fig,...
'Position',[125 150 100 78],...
'Multiselect','on',...
'ValueChangedFcn',@selectionChanged);
% ValueChangedFcn callback
function selectionChanged(src,event)
txt.Value = src.Value;
end
end
best regards
EDIT:
I noticed that I Have to press Ctrl for MultiSelect. How unconvenient.
Is there a way to modify inputs such that they are interpreted always as ctrl+left click?

Respuesta aceptada

Jonas
Jonas el 13 de Feb. de 2023
Editada: Jonas el 16 de Feb. de 2023
I tried to circumvent the ctrl modofier in such a way, that I look into the event's previous value and delete/save as necessary. Now, there is also always one option selected
I modified the callback as follows:
function selectionChanged(src,evt)
prevVal=evt.PreviousValue;
currVal=src.Value;
if strcmp(fig.SelectionType,'normal') % to preserve ctrl behavior
isThere=ismember(prevVal,currVal);
if any(isThere)
prevVal=prevVal(~isThere);
else
prevVal=[prevVal currVal];
end
src.Value=prevVal;
end
end
please note that with the current state, the bahavior with ctrl left click changes and does not work as intended anymore.
EDIT: edited code to properly preserve ctrl click behavior

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by