unchecked checkbox when another checkbox was checking
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
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.
0 comentarios
Ver también
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!