Change the check box value of a Matlab Tree Node Check Box via code
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear mathworks community,
I am currently developing a Matlab GUI and my main element is a Matlab Tree (Check Box) in the Matlab App Designer.
As there are potentially more than 30 Nodes aavalaible to select, I want to add a "SELECT ALL" check box to the gui, that changes the value of all check boxes of the Tree Node to checked or unchecked. Is there a way to do so? Is there a command to change the value of the check box of the node?
If there is no easy way to do it, can you imagine a workaround?
Thanks in advance for your help!
0 commentaires
Réponse acceptée
Cameron
le 14 Fév 2023
Can you not make them second level nodes?
fig = uifigure;
cbt = uitree(fig,'checkbox','Position',[20 20 150 150]);
% First level nodes
category1 = uitreenode(cbt,'Text','All','NodeData',[]);
% Second level nodes.
p1 = uitreenode(category1,'Text','Option 1');
p2 = uitreenode(category1,'Text','Option 2');
p3 = uitreenode(category1,'Text','Option 3');
p4 = uitreenode(category1,'Text','Option 4');
p5 = uitreenode(category1,'Text','Option 5');
3 commentaires
Cameron
le 14 Fév 2023
fig = uifigure;
cbt = uitree(fig,'checkbox','Position',[20 20 150 150]);
% Second level nodes.
p1 = uitreenode(cbt,'Text','Option 1');
p2 = uitreenode(cbt,'Text','Option 2');
p3 = uitreenode(cbt,'Text','Option 3');
p4 = uitreenode(cbt,'Text','Option 4');
p5 = uitreenode(cbt,'Text','Option 5');
%if you don't run this next line, none of the boxes will be checked.
cbt.CheckedNodes = cbt.Children;
Are Mjaavatten
le 16 Jan 2024
Modifié(e) : Are Mjaavatten
le 16 Jan 2024
I needed to start with all boxes checked. This function does this for two levels.
function checkbox_tree_check_all(tree)
topNodes = tree.Children;
allNodes = topNodes;
for i = 1:numel(topNodes)
allNodes = [allNodes;topNodes(i).Children];
end
tree.CheckedNodes = allNodes;
end
Are there more elegant ways?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!