Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / How to get all child nodes of selected parent?

How to get all child nodes of selected parent?

New Discussion
michael
michael asked on Sep 23, 2008 3:12 PM

 

Ultratree:

example scenario: 

parent

         child1

                 child3

                       child4

        child2

             child 5

 

how can I get all parent1 child nodes?????

thanks for any reply…..

 

 

 

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Sep 23, 2008 2:35 PM

    tree.Nodes["parent"].Nodes will return the child nodes collection of the parent node. 

    If you want all descendants, and not just the direct children, then you will need to walk down the tree recursively. 

  • 0
    Brian Fallon
    Brian Fallon answered on Sep 23, 2008 3:12 PM

    void ultraTree1_AfterSelect(object sender, SelectEventArgs e)
    {
        UltraTreeNode node = e.NewSelections.Count == 1 ? e.NewSelections[0] : null;
        if ( node != null )
        {
            List<UltraTreeNode> descendants = this.GetAllDescendants( node );
            bool stop = true;
        }
    }

    private List<UltraTreeNode> GetAllDescendants( UltraTreeNode node )
    {
        List<UltraTreeNode> retVal = new List<UltraTreeNode>();
        this.GetAllDescendants( node.Nodes, retVal );
        return retVal;
    }

    private void GetAllDescendants( TreeNodesCollection nodes, List<UltraTreeNode> descendants )
    {
        foreach ( UltraTreeNode node in nodes )
        {
            descendants.Add( node );

            if ( node.HasNodes )
                this.GetAllDescendants( node.Nodes, descendants );
        }
    }

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
michael
Favorites
0
Replies
2
Created On
Sep 23, 2008
Last Post
17 years, 5 months ago

Suggested Discussions

Tags

Created by

Created on

Sep 23, 2008 3:12 PM

Last activity on

Feb 16, 2026 9:41 PM