How to copy uitree content in AppDesigner from app.uitree_1 to app.uitree_2?
5 ビュー (過去 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!