unchecked checkbox when another checkbox was checking

19 visualizaciones (últimos 30 días)
Yuli Hartini
Yuli Hartini el 27 de Abr. de 2017
Respondida: Hamza Kayani el 13 de Jun. de 2021
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..

Respuestas (2)

Jan
Jan el 27 de Abr. de 2017
This is a job for radio-buttons, not for check-boxes.

Hamza Kayani
Hamza Kayani el 13 de Jun. de 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.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by