I want to a dynamic recursive method to expand treeview

8 posts, 1 answers
  1. Sagar
    Sagar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 02 Dec 2010 Link to this post

    Hi, 
        I am having a tree view in which there is no limit for adding the child's level (may be between 20-25) .But i could not find a recursive method which can recursively expand a particular child node (which is the result of the search i am providing).Please help.

    Thanks & Regards,
    Sagar
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 Dec 2010 Link to this post

    Hello Sagar,

    This will expand all nodes for you. Or colapse them

    For Each node As Telerik.WinControls.UI.RadTreeNode In Me.RadTreeView1.Nodes
        node.ExpandAll()
        'node.CollapseAll()
    Next

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sagar
    Sagar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 02 Dec 2010 Link to this post

    Hi, Richard,
                     Thanks, but i want to expand a particular node and the parents of the particular Node (node may be End Node or middle One)..

    Thanks & Regards,
    Sagar
  5. Sagar
    Sagar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 03 Dec 2010 Link to this post

    In Rad Asp.net controls we get the one line to expand all the parent nodes.

    i.e:
    node.expandparentnode=true;

    But what is there equivalent to it in WinForms..
  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 03 Dec 2010 Link to this post

    Hello Sagar,

    As far as I know there is no equivilent is WinForms. You would have to loop over the nodes calling the Expand methid on each one.

    If yu want to do this recursively with some conditions attached, have a look at this code library article on searching a tree view which shows how to drill down through a tree view. This can easily be updated to expand or collspase particular nodes under a given condition.

    Hope that helps but let me know if you have any other questions
    Richard
  7. Sagar
    Sagar avatar
    6 posts
    Member since:
    Oct 2010

    Posted 07 Dec 2010 Link to this post

    Hi, Richard .
             i got time today to come back on this topic. And it clicked to me after some time. Anyways your post gave me some "IDEA". 


    Thanks & Regards,
    Sagar
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Dec 2010 Link to this post

    Glad that helped.
    Richard
  9. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 08 Dec 2010 Link to this post

    Hello Sagar,

    You can use the following code snippet to achieve this behavior:

    private void ExpandParents(RadTreeNode childNode)
    {
        Stack<RadTreeNode> nodeStack = new Stack<RadTreeNode>();
        nodeStack.Push(childNode.Parent);
     
        while (nodeStack.Count > 0)
        {
            RadTreeNode current = nodeStack.Pop();
            if (current == null)
            {
                break;
            }
     
            current.Expand();
            nodeStack.Push(current.Parent);
        }
    }

    I hope this helps.

    Regards,

    Julian Benkov
    the Telerik team

     

    Get started with RadControls for WinForms with numerous videos and detailed documentation.
Back to Top
UI for WinForms is Visual Studio 2017 Ready