How to programatically select nodes of an uitree in AppDesigner?
    18 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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).
0 件のコメント
採用された回答
  Kevin Holly
    
 2022 年 7 月 22 日
        
      編集済み: Kevin Holly
    
 2022 年 7 月 22 日
  
      Ron,
Please see the app attached.
The callback in attach app is:
  function ButtonPushed(app, event)
            app.Node.Tag = 'Image';
            app.Node4.Tag = 'Image';
            app.Node_3.Tag = 'Image';
            for ii = 1:length(app.Tree.Children)
%                 if strcmp(app.Tree.Children(ii).Tag,'Image')
%                     app.Tree.CheckedNodes = [app.Tree.CheckedNodes; app.Tree.Children(ii)];
%                 end
                for jj = 1:length(app.Tree.Children(ii).Children)
                    if strcmp(app.Tree.Children(ii).Children(jj).Tag,'Image')
                        app.Tree.CheckedNodes = [app.Tree.CheckedNodes; app.Tree.Children(ii).Children(jj)];
                    end
                    for kk = 1:length(app.Tree.Children(ii).Children(jj).Children)
                        if strcmp(app.Tree.Children(ii).Children(jj).Children(kk).Tag,'Image')
                            app.Tree.CheckedNodes = [app.Tree.CheckedNodes; app.Tree.Children(ii).Children(jj).Children(kk)];
                        end
                    end
                end
            end 
  end
If you wanted to just select 2nd layer of nodes, you could do the folllowing:
            for ii = 1:length(app.Tree.Children)
                for jj = 1:length(app.Tree.Children(ii).Children)
                    if strcmp(app.Tree.Children(ii).Children(jj).Tag,'Image')
                        app.Tree.CheckedNodes = [app.Tree.CheckedNodes; app.Tree.Children(ii).Children(jj)];
                    end
                end
            end
その他の回答 (1 件)
  Cris LaPierre
    
      
 2022 年 7 月 22 日
        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 件のコメント
  Cris LaPierre
    
      
 2022 年 7 月 22 日
				I see you got an answer while I was working on mine. I'll leave it in case it is helpful.
参考
カテゴリ
				Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


