Can I use restriction of selections in multiple mode in listdlg?

4 ビュー (過去 30 日間)
Varun Jadhav
Varun Jadhav 2016 年 8 月 19 日
回答済み: TED MOSBY 2025 年 8 月 21 日 6:12
Hi,
I am using listdlg to list out a file showing multiple currents outputs.
I always need to select only three currents at a time hence need to give restriction in 'SelectionMode' of 3 to avoid user errors.
This is the function I call when I need to do the assignment of the amplifier.
function listboxMIa_Callback(hObject, eventdata, handles)
CurrentArrayLabel = evalin('base', 'CurrentArrayLabel');
[MI_aheader,~] = listdlg('PromptString',{'Select the current outputs for Channel A:' '(Please select a maximum of 3 outputs)'},...
'Name', 'Amplifier Assignment',...
'ListSize', [250, 125],...
'ListString',CurrentArrayLabel);
assignin('base', 'MI_aheader', MI_aheader);
Is this possible?
Regards,
Varun Jadhav

回答 (1 件)

TED MOSBY
TED MOSBY 2025 年 8 月 21 日 6:12
Hi,
As of today, listdlg can only do single vs multiple - it cannot limit the number of selections by itself. You have to manually validate the number of selections.
need = 3;
[idx, ok] = listdlg('PromptString', {sprintf('Select exactly %d items:', need)}, ...
'SelectionMode','multiple', ...
'ListString', CurrentArrayLabel, ...
'ListSize', [250 125], ...
'Name','Amplifier Assignment');
if ~ok, idx = []; return; end
if numel(idx) == need, return; end
uiwait(warndlg(sprintf('Select exactly %d items (you picked %d).', need, numel(idx)), ...
'Invalid selection','modal'));
You may contact MathWorks Technical Support if you want this feature to be added!
Hope it helped.

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by