How to get access all nodes in a treeview?

3 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. UI for WinForms is Visual Studio 2017 Ready
  4. 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);


Back to Top