Clear Filters
Clear Filters

unchecked checkbox when another checkbox was checking

11 views (last 30 days)
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..

Answers (2)

Jan
Jan on 27 Apr 2017
This is a job for radio-buttons, not for check-boxes.

Hamza Kayani
Hamza Kayani on 13 Jun 2021
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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!