How can I change the state of multiple CheckBoxes in App designer?

3 次查看(过去 30 天)
I am working on a GUI that has 200 checkboxes. They have tags like "app.CheckBox_X_Y", where X can have values from 1 to 50 and Y can have values from 1 to 4.
I'd like to change the state of the last checkbox and this must change the state of all others at once.
I tried the following code, but it's giving me error "Error using set - Invalid handle". Can someone help me?
function CheckBoxPelota_X_1ValueChanged(app, event)
if app.CheckBoxPelota_X_1.Value == 0
for cont1 = 1:1:50
for cont2 = 1:1:4
set(sprintf('app.CheckBoxPelota_%d_',cont1),'Value', 1);
end
end
else
for cont1 = 1:1:50
for cont2 = 1:1:4
set(sprintf('app.CheckBoxPelota_%d_',cont1),'Value', 0);
end
end
end
end

采纳的回答

Voss
Voss 2023-12-21
I'll assume that the description, "tags like "app.CheckBox_X_Y", where X can have values from 1 to 50 and Y can have values from 1 to 4", is accurate, that CheckBoxPelota_X_1ValueChanged is the ValueChangedFcn of the top-most "Marcar Todos" checkbox, that that checkbox's tag is CheckBoxPelota_X_1, and that (un)checking it should set the Value of all other checkboxes in the top row to match the Value of app.CheckBoxPelota_X_1 and not effect the checkboxes in the other three rows.
function CheckBoxPelota_X_1ValueChanged(app, event)
val = app.CheckBoxPelota_X_1.Value;
for cont1 = 1:50
set(app.(sprintf('CheckBox_%d_1',cont1)),'Value',val);
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by