Change the check box value of a Matlab Tree Node Check Box via code
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Cameron
il 14 Feb 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 Commenti
Cameron
il 14 Feb 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
il 16 Gen 2024
Modificato: Are Mjaavatten
il 16 Gen 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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!