How to get access all nodes in a treeview?

5 posts, 1 answers
  1. Mohsen
    Mohsen avatar
    13 posts
    Member since:
    Jan 2013

    Posted 09 Jul 2013 Link to this post

    Hi,
    I wanna access all nodes(include all treeviews) in RadTreeView,I try to use Foreach like:
    foreach (var node in RadTreeView1.Nodes)
              {
     
              }
    but it return just top level nodes.How can I access all nodes in a foreach?

    Regards,
    Mohsen.
  2. Mohsen
    Mohsen avatar
    13 posts
    Member since:
    Jan 2013

    Posted 12 Jul 2013 Link to this post

    Anyone?
  3. Answer
    Mohsen
    Mohsen avatar
    13 posts
    Member since:
    Jan 2013

    Posted 14 Jul 2013 Link to this post

    I find a simple solution with recursive method to enumerate treeview nodes, I write that here for those one need that in the future!

    private static void CheckTreeViewNodes(IEnumerable<RadTreeNode> treeNodeCollection)
            {
                foreach (var node in treeNodeCollection)
                {
                    //Do some thing you need to do!
                    CheckTreeViewNodes(node.Nodes);
                }
            }

    So, If you want to get all nodes in a treeview, start it with blow few code:
    CheckTreeViewNodes(treeView.Nodes);


  4. Dickson
    Dickson avatar
    6 posts
    Member since:
    Sep 2015

    Posted 03 Aug 2018 in reply to Mohsen Link to this post

    Thank you, I'm am using it right now! 
  5. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 03 Aug 2018 Link to this post

    Hello,

    There is a method for this as well:
    var allNodes = tempTree.TreeViewElement.GetNodes().ToList();

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top