Modify order of RadTreeView Node Items

2 posts, 1 answers
  1. Robert
    Robert  avatar
    68 posts
    Member since:
    Feb 2009

    Posted 21 Oct 2011 Link to this post

    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);
                             
           }
  2. Answer
    Plamen
    Admin
    Plamen avatar
    2730 posts

    Posted 24 Oct 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top