listbox cannot make it select single or none, it has to be single or multiple.

4 ビュー (過去 30 日間)
raym
raym 2023 年 2 月 26 日
コメント済み: raym 2023 年 2 月 26 日
Hi,I am using listbox to select item.
The aim is to select only one, or no select.
I set min to 0 and max to 1, but the ui does not allow select none.
If I set min to 0 and max to 2, now the ui can select none, but also enables multiple select.
% not allow select none.
figure;uicontrol('Style','listbox',...
'String',{'rr','tt','gg'},...
'position',[10,20,100,200],...
'min',0,...
'max',1)
% allow select none, but also allow multiple select
figure;uicontrol('Style','listbox',...
'String',{'rr','tt','gg'},...
'position',[10,20,100,200],...
'min',0,...
'max',2)

採用された回答

Simon Chan
Simon Chan 2023 年 2 月 26 日
To my understanding, multiple select does not allow select none, it has automatically select the first one unless you assign some other value in its 'Value' properties.
As a workaround, you can assign an empty item in the first selection and the listbox will automatically select the first one unless the user select some other item.
By doing that, the default selection, which is the empty one, can simulate select none in your case.
figure;uicontrol('Style','listbox',...
'String',{'','rr','tt','gg'},... % Assign an empty one as the first selection
'position',[10,20,100,200],...
'min',0,...
'max',1)
  1 件のコメント
raym
raym 2023 年 2 月 26 日
multiple select indeed could select none by Ctrl-Click.
The .Value will return [] if select none.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by