CheckBoxTree - Programmatic Checking/Unchecking of Nodes

How can I programmatically check/uncheck nodes of a CheckBoxTree?
edit: spelling

댓글 수: 1

I understand how to check nodes
treeRoot = uitree("checkbox");
node1 = uitreenode(treeRoot, text="A - level 1");
node2 = uitreenode(treeRoot, text="B - level 1");
node3 = uitreenode(node1, text="A - level 2");
check A, which implicitly checks A level 1&2
treeRoot.CheckedNodes = node1;
check B
treeRoot.CheckedNodes = [treeRoot.CheckedNodes; node2];
How to uncheck A and its child?? Checking implicitly sets children as well, but not unchecking? Not sure if this was intended by @MathWorks Support Team
treeRoot.CheckedNodes(treeRoot.CheckedNodes == node1) = []; % does not work, because node2 is still toggled
This works, but it seems like I need to keep track of the tree myself?
treeRoot.CheckedNodes(ismember(treeRoot.CheckedNodes, [node1,node3])) = [];

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

 채택된 답변

Randy Price
Randy Price 2022년 4월 29일

1 개 추천

Resolved - assign nodes of the CheckBoxTree to its "SelectedNodes" property.

댓글 수: 2

STEVEN SATTERFIELD
STEVEN SATTERFIELD 2023년 1월 12일
편집: John Kelly 2023년 10월 23일
It is not the "SelectedNodes" property, but rather the "CheckedNodes" property to which you must add or remove nodes. What would be helpful is an example of how to do that.
yes, please give more information about that

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

추가 답변 (1개)

Kris Hoffman
Kris Hoffman 2023년 3월 3일
편집: Kris Hoffman 2023년 3월 3일
I'm using app designer and came across this issue. The above answers gave me the idea to simply address them in the 'CheckedNodes' attribute of the tree.
The first entry is put into the 'CheckedNodes' list does not need to be indexed.
app.Tree.CheckedNodes = app.Tree.Children(i).Children(j)
The following code adds the 3rd child of the 5th parent entry (I know it says children twice), to the end of the entries in the 'CheckedNodes' attribute.
app.Tree.CheckedNodes(end+1) = app.Tree.Children(5).Children(3)
then checking the checked nodes:
app.Tree.CheckedNodes
The last entry is there!
You can also add all entries under a "parent" node as follows:
app.Tree.CheckedNodes(end+1) = app.Tree.Children(5).Children
Now to remove a specific entry, as far as I know, you would need to know where it is in the TreeNode array. I was able to uncheck a box by using the following code.
app.Tree.CheckedNodes(2) = '';
The entry was removed and box, unchecked!
Hope that helps!

댓글 수: 1

string compare and everything that ai playground offers as an solution to find the place where the node is in the array doesn't work

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 4월 28일

댓글:

2025년 7월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by