필터 지우기
필터 지우기

unchecked checkbox when another checkbox was checking

조회 수: 11 (최근 30일)
Yuli Hartini
Yuli Hartini 2017년 4월 27일
답변: Hamza Kayani 2021년 6월 13일
I have four checkbox using GUI, and I want to force a checkbox to be unchecked based on checking another checkbox. So, when the user selects one option, I want to de-select other options.. Please help me for that! Thank you so much..

답변 (2개)

Jan
Jan 2017년 4월 27일
This is a job for radio-buttons, not for check-boxes.

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.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by