Treeview AutoExpand By Value

12 posts, 1 answers
  1. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 16 May 2011 Link to this post

    Hi, i have a treenode that is connected to to a SQL datasource and i am adding a search capability to the tree that when a user selects the PK of that node the tree loaded will be expanded to point at that node that owns that PK.

    How can this be done?

    Thanks!
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 May 2011 Link to this post

    Hello Bryan,

    In order to implement this, you can follow the same logic in the following code library.
    TreeNode searching.

    Thanks,
    Shinu.
  3. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 17 May 2011 Link to this post

    @Shinu

    awesome :D

  4. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 17 May 2011 Link to this post

    just found out that it woulnt find a third tier Node, any solution for this?

    such as Parent 1 
    child1 of parent1
                                                  child of child1
  5. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 19 May 2011 Link to this post

    Hi Bryan,

    In order to make Shinu's "solution" to work, you can make the method recursive and remove the nested loop.


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 19 May 2011 Link to this post

    a sample would be great to have sir!
  7. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 20 May 2011 Link to this post

    Hi Bryan,

    Here you are, this should do the job:
    void LoopNodes(RadTreeNodeCollection nodes)
    {
        foreach (RadTreeNode node in nodes)
        {
            // process node
      
            if (node.Nodes.Count > 0)
            {
                LoopNodes(node.Nodes);
            }
        }
    }


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  8. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 20 May 2011 Link to this post

    @Nikolay

    i should responded earlier but what i found out is that i have always located the node that was being searched..
    the problem was expanding the parent of the multi level nodes..

    using node.parent.prev does work but sometimes it doesnt..is there a better way of doing it the telerik way?

    what i also did was use the get path and loaded those in an array with the ID and expanding the nodes by its id/value this is what i did such as id = pk in path (4-79-100-210) expand(4) expand(79) expand (100) etc..
  9. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 20 May 2011 Link to this post

    Hello Bryan,

    I am not exactly sure I understand what seems to be the problem that you experience.
    Could you, please, explain it in a bit more detail?

    What I am definitely sure, is that this code, cannot span more than the second level of nodes:
    //FindTreeNode function 
    private void FindTreeNode(String treeNode) 
        //Looping through each node in the treeview 
        foreach (RadTreeNode node in RadTreeView1.Nodes) 
        
            //Checking the node name with the node name entered in the textbox 
            if (node.Text == treeNode) 
            
                //if the node name equal to the node name entered in the textbox setting the selected property of the node to true 
                node.Selected = true
            
            else 
            {                
                node.Selected = false
            
            //Looping through the child nodes  
            for (int i = 0; i < node.Nodes.Count; i++) 
            
               if (node.Nodes[i].Text == treeNode) 
                
                    //if the node name equal to the node name entered in the textbox setting the selected property of the node to true and expanding that node. 
                    node.Expanded = true
                    node.Nodes[i].Selected = true
                
                else 
                
                    node.Nodes[i].Selected = false
                
            
        
    }


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  10. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 20 May 2011 Link to this post

    @Nikolay

    what i mean is that i thought my query was not loading every node, but it was..and find node by value and getting the path confirms this, and even expanding the whole tree and locating the node confirms this, however is there a way to expand the node by the value?and that including the parent(s) node?
  11. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 23 May 2011 Link to this post

    Hi Bryan,

    You can get the node using the FindNodeByValue method of RadTreeView's.
    Then you can expand its parent nodes using the ExpandParentNodes method of RadTreeNode's and expand the node itself - "node.Expand = true;".


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  12. Bryan
    Bryan avatar
    25 posts
    Member since:
    Jun 2012

    Posted 23 May 2011 Link to this post

    @Nikolay

     


    this is what i needed "ExpandParentNodes"
    replaced my 5 line code!

    Thanks!
Back to Top