unchecked checkbox when another checkbox was checking
22 views (last 30 days)
Show older comments
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..
0 Comments
Answers (2)
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.
0 Comments
See Also
Categories
Find more on Interactive Control and Callbacks 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!