필터 지우기
필터 지우기

Change the check box value of a Matlab Tree Node Check Box via code

조회 수: 34 (최근 30일)
Tom
Tom 2023년 2월 14일
편집: Are Mjaavatten 2024년 1월 16일
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!

채택된 답변

Cameron
Cameron 2023년 2월 14일
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
Cameron
Cameron 2023년 2월 14일
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
Are Mjaavatten 2024년 1월 16일
편집: Are Mjaavatten 2024년 1월 16일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by