This is a migrated thread and some comments may be shown as answers.

Find Lower Level Nodes

1 Answer 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Corey
Top achievements
Rank 1
Corey asked on 13 Mar 2012, 03:17 PM
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

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 16 Mar 2012, 09:30 AM
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.
Tags
TreeView
Asked by
Corey
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or