How to copy uitree content in AppDesigner from app.uitree_1 to app.uitree_2?
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello,
is there any simple (or complex) way to copy THE FULL TREE from object A (app.uitree_A) to object B (app.uitree_B)?
Seems like a reasonable feature to have, doesn't it?
Thank You!
댓글 수: 1
Benjamin Turner
2023년 2월 6일
Hi,
I have the same problem / want to do the same thing.
Do you hava a solution by now by any chance?
Thanks!
답변 (1개)
Benjamin Turner
2023년 2월 6일
I just quickly put something together:
I created one function to find the parent treeNode:
function [Node] = searchParentNode(Node)
Node = Node.Parent;
if ~strcmp(Node.Type,"uitreenode")
return
end
Node=searchParentNode(Node);
end
And then a function to recursively copy the nodes
function createRecursiveNodes(Parent, Node)
for n = Node.Children'
p = uitreenode(Parent, Text=n.Text, NodeData=n.NodeData, Tag=n.Tag, Icon=n.Icon);
createRecursiveNodes(p, n);
end
end
Here an example:
tree = uitree(); %create a tree
%create some example nodes
parent = uitreenode(tree,Text='AAA');
titles = 'abc';
for i = 1:3
uitreenode(parent,Text=titles(i), NodeData=rand(1))
end
parent = uitreenode(tree,Text='BBB');
titles = 'dce';
for i = 1:3
uitreenode(parent,Text=titles(i), NodeData=rand(1))
end
TreeNodes = tree.CheckedNodes;
PNode= searchParentNode(TreeNodes(1)); %just pick any of the selected nodes and search for the UITree parent.
You can of course put as well the tree directly (it just wasnt possible in my case):
PNode = tree
then copy everything:
tree2 = uitree()
app.createRecursiveNodes(tree2,PNode); % Copy all Children recursively Top-to bottom
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!