How to copy uitree content in AppDesigner from app.uitree_1 to app.uitree_2?

5 visualizaciones (últimos 30 días)
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 comentario
Benjamin Turner
Benjamin Turner el 6 de Feb. de 2023
Hi,
I have the same problem / want to do the same thing.
Do you hava a solution by now by any chance?
Thanks!

Iniciar sesión para comentar.

Respuestas (1)

Benjamin Turner
Benjamin Turner el 6 de Feb. de 2023
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

Categorías

Más información sobre Dialog Boxes en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by