Find Lower Level Nodes

2 posts, 0 answers
  1. Corey
    Corey avatar
    9 posts
    Member since:
    Mar 2012

    Posted 13 Mar 2012 Link to this post

    Is there any way for me to pull data from lower level nodes. LIke I have a root  node populating the parent nodes nd that populates the child nodes.. and so on and so forth. But im making a folder system and if a user added a new folder i have no way without hardcoding it to do what i need it too.. and i dont want to limit the folder numbers.. heres some code to show you waht im attempting. I want to do the foreach loops when the lower level nodes contain nodes.. anyway to do this not hardcoded
    foreach (RadTreeNode node in rtvFiles.Nodes)
                {
                    foreach (RadTreeNode parentNode in node.Nodes)
                    {
                        foreach (RadTreeNode childNode in parentNode.Nodes)
                        {
                            //if (parentNode.Text == "share")
                            //{
     
                            if (childNode.Checked)
                            {
                                FilesCOL file = FilesDAL.SelectByName(childNode.Text, int.Parse(childNode.Attributes["FileID"]));
                                c = file.FilePath;
                                b = childNode.Text;
                                d = file.FileID.ToString();
                            }
                            else
                            { if(childNode.Checkable==false)
                                foreach (RadTreeNode babyNode in childNode.Nodes)
                                {
                                     
                                    if (babyNode.Checked)
                                    {
                                        FilesCOL file = FilesDAL.SelectByName(babyNode.Text, int.Parse(babyNode.Attributes["FileID"]));
                                        c = file.FilePath;
                                        b = babyNode.Text;
                                        d = file.FileID.ToString();
                                    }
    }
    }
    ome code to show you waht im attempting
  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 16 Mar 2012 Link to this post

    Hi Corey,

    Could you elaborate a bit on your requirement? Is the tree generated from the folder system, or the other way around? Also, where is the new folder created and what action should take place in this case?

    In general if you want to go through all nodes of the treeview, there are a couple of ways you can do that:

    1. You can call the GetAllNodes() function of the treeview, which gives you a collection of all the nodes inside the treeview. Each node has a ParentNode property which you can use to get a reference to the node's parent.

    2. You can use recursion. For instance:
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (RadTreeNode node in RadTreeView1.Nodes)
        {
            TraverseNodes(node);
        }
    }
     
    protected void TraverseNodes(RadTreeNode node)
    {
        //Do something
     
        if (node.Nodes.Count > 0)
        {
            foreach (RadTreeNode childNode in node.Nodes)
            {
                TraverseNodes(childNode);
            }
        }
    }

     
    Kind regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top