How to get only one checkbox that can be checked

12 ビュー (過去 30 日間)
Yuli Hartini
Yuli Hartini 2017 年 4 月 27 日
コメント済み: Hamza Kayani 2021 年 6 月 13 日
I use some checkbox in gui (checkbox A, B, C). How to get only one checkbox that can be checked. If I check the checkbox B, then the selected checkbox B, then I changed my mind want to check the checkbox A, then the selected checkbox A. Thank you
  1 件のコメント
Hamza Kayani
Hamza Kayani 2021 年 6 月 13 日
Although what you are looking for is specifically in domain of radio buttons however, there is a way around when using check boxes as well. I have discovered a cool way to do so.
Assuming you have three check boxes, head over to the callback function of the first check box and paste the following if-else statement:
function checkbox1_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'value')
set(handles.checkbox2,'Enable','off')
set(handles.checkbox3,'Enable','off')
else
set(handles.checkbox2,'Enable','on')
set(handles.checkbox3,'Enable','on')
end
%%%%%%%%%%
Now do the same with the callbacks of other two checkboxes but change the tag or name of the checkboxes accordingly. This way, the user can only check one checkbox at a time while the remaining checkboxes will be disabled.

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

回答 (1 件)

Jan
Jan 2017 年 4 月 27 日
編集済み: Jan 2017 年 4 月 27 日
Please do not ask a question twice.
  1 件のコメント
Margareta Drozdikova
Margareta Drozdikova 2018 年 2 月 25 日
Hi, try this. For example, I have two checkboxes (checkbox1 and checkbox2). In the first:
if true
% code
end
handles.value=get(handles.checkbox1,'Value');
if handles.value==1 %%it means, is checked
set(handles.checkbox2,'Visible','off')
else
set(handles.checkbox2,'Visible','on')
end
So, If I checked the first, the second is invisible, write it in the second too

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by