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

Modify order of RadTreeView Node Items

1 Answer 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 21 Oct 2011, 03:39 PM
I'm working with the RadTreeView, and the RadTreeView is being loaded from a folder structure on an FTP Server;

My question is how best can I change the order programmatically with C# - move a node value from last item to the seventh item;

The code snippet below displays how the RadTreeView is being loaded with C#, and I am able locate the node value - which needs to be moved in the RadTreeView hiarchy;

Thanks in advance for any insight;  Best regards - Rob  
private void BindTreeToDirectory(string virtualPath, RadTreeNode parentNode)
   {    
       string physicalPath = Server.MapPath(virtualPath);
       string[] directories = Directory.GetDirectories(physicalPath);
       foreach (string directory in directories)
       {
           RadTreeNode node = new RadTreeNode(Path.GetFileName(directory));
           node.Value = virtualPath + "/" + Path.GetFileName(directory);
           node.ImageUrl = "~/TreeView/Img/Vista/folder.png";
           node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
           //if (node.Value == "/Customers/Maines Paper & Foodservice/Side Letters")
           if (node.Value == "/Customers/Maines Paper & Foodservice/Maintenance Provider AIM")
           {
               //var index = parentNode.
               //     directories[8];
               //var index = directories[7];
           }
           else
           {
               parentNode.Nodes.Add(node);
           }
           //RadTreeNode nodeSideLetters = new RadTreeNode("/Customers/Maines Paper & Foodservice/Side Letters");
           //parentNode.Nodes.Add(nodeSideLetters);
                         
       }

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 24 Oct 2011, 10:14 AM
Hello Robert ,

Here in yellow is the code that I added to the Directory Structure demo that inserted a node in the second position:
private void BindTreeToDirectory(string virtualPath, RadTreeNode parentNode)
        {
            string physicalPath = Server.MapPath(virtualPath);
            string[] directories = Directory.GetDirectories(physicalPath);
            RadTreeNode addAtSecound = new RadTreeNode();
            foreach (string directory in directories)
            {
                RadTreeNode node = new RadTreeNode(Path.GetFileName(directory));
                node.Value = virtualPath + "/" + Path.GetFileName(directory);
                node.ImageUrl = "~/TreeView/Img/Vista/folder.png";
                 
                node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
 
                if (node.Value == "~/TreeView/Examples/Programming")
                {
                    addAtSecound = node;
                     
                    continue;
                }
                else
                {
                    parentNode.Nodes.Add(node);
                }
                 
            }
            parentNode.Nodes.Insert(2, addAtSecound);

Hope this will help.

Best wishes,
Plamen Zdravkov
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
Robert
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or