How to programatically select nodes of an uitree in AppDesigner?
Show older comments
Hi,
I would like to programatically select nodes of a an uitree in AppDesigner. I have

And would like to select all nodes with the Tag "Image". (I alreade have set this Tag during creating the tree).
Accepted Answer
More Answers (1)
Cris LaPierre
on 22 Jul 2022
You can use app.Tree.SelectedNodes
I found this example helpful. There will need to be some modifications to get it to work inside an app. You could use the names of the nodes to select, but that gets cumbersome with the names you use.
app.Tree.SelectedNodes = [app.C1tifNode]
I find it easier to use the tree structure to select multiple nodes (note you must turn Multiselect on. Select the tree in your component browser and expand the interactivity property). For example, this code selects the 2nd and 3rd child nodes under the 2nd node.
app.Tree.SelectedNodes = app.Tree.Children(2).Children(2:3);
For your final question on using the Tag property to select nodes, the only way I could find to do this was to loop through each node. I don't love this solution, but it works.
nodes = [];
for n = 1:length(app.Tree.Children)
for n1 = 1:length(app.Tree.Children(n).Children)
if strcmp(app.Tree.Children(n).Children(n1).Tag,'image')
nodes = [nodes app.Tree.Children(n).Children(n1)];
end
end
end
app.Tree.SelectedNodes = nodes
2 Comments
Cris LaPierre
on 22 Jul 2022
I see you got an answer while I was working on mine. I'll leave it in case it is helpful.
Ron Hoebe
on 22 Jul 2022
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!