only for the leaf nodes the icons are changed

3 posts, 0 answers
  1. Laurentiu
    Laurentiu avatar
    9 posts
    Member since:
    Oct 2008

    Posted 10 Nov 2008 Link to this post

    I need to change the branch or whole tree icons when I select an option from the menu.
    On OnClientContextMenuItemClicked I call the recusive function for changing the icons

    My problem is that only for the leaf nodes  the icons are changed .

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestTreeView.Default" %> 
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
     
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server">  
        <title>Untitled Page</title> 
    </head> 
     
    <script type="text/javascript">  
         function SetImageUrl(node, imageUrl)  
        {  
            node.set_imageUrl(imageUrl);     
            node.set_selectedImageUrl(imageUrl);   
              
            for (var i = 0; i < node.get_nodes().get_count(); i++)     
            {    
                SetImageUrl(node.get_nodes().getNode(i), imageUrl);  
            }    
        }  
          
        function OnClientContextMenuItemClicked(sender, args)  
        {  
            var menuItem = args.get_menuItem();     
            var node     = args.get_node();     
        
            sender.trackChanges();   
            switch(menuItem.get_value())     
            {     
                case "FullCategory":  
                    SetImageUrl(node, "../Images/circle_red.png");  
                    break;     
                case "PartialCategory":     
                    SetImageUrl(node, "../Images/circle_green.png");  
                    break;     
                case "RemoveCategory":  
                    SetImageUrl(node, "../Images/Folder.gif");  
                      
            }     
            sender.commitChanges();  
        }  
              
          
        </script> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <asp:ScriptManager ID="scriptManager1" runat="server" /> 
             <telerik:RadTreeView id="t" runat="server" Height="470px" Visible = "true" 
                                OnClientContextMenuItemClicked = "OnClientContextMenuItemClicked" > 
                                  
                                <ContextMenus>   
                                    <telerik:RadTreeViewContextMenu ID="AppRoleMenu" ClickToOpen="True" runat="server" >   
                                     <Items> 
                                       <telerik:RadMenuItem Text="Full Category"    Value="FullCategory"></telerik:RadMenuItem> 
                                       <telerik:RadMenuItem Text="Partial Category" Value="PartialCategory"></telerik:RadMenuItem> 
                                       <telerik:RadMenuItem Text="Remove  Category" Value="RemoveCategory"></telerik:RadMenuItem> 
                                     </Items>    
                                    </telerik:RadTreeViewContextMenu> 
                                </ContextMenus>   
              </telerik:RadTreeView> 
          
        </div> 
        </form> 
    </body> 
    </html> 
     
     
     
    the code behind :  
     
     
    using Telerik.Web.UI;  
    using Telerik.QuickStart;  
     
     
    namespace TestTreeView  
    {  
        public partial class Default : System.Web.UI.Page  
        {  
            string ImageUrl = "../Images/Folder.gif";  
     
            protected void Page_Load(object sender, EventArgs e)  
            {  
                LoadTree();  
            }  
     
            protected void LoadTree()  
            {  
                string[] arr1 = new string[]{"node1.1","node1.2","node1.3", "node1.4"};  
                string[] arr2 = new string[]{"node2.1","node2.2","node2.3", "node2.4"};  
                string[] arr3 = new string[]{"node3.1","node3.2","node3.3", "node3.4"};  
                  
                RadTreeNode root  = new RadTreeNode("root", "0");  
                root.ImageUrl = ImageUrl;  
                t.Nodes.Add(root);    
     
                root.Nodes.Add(CreateNodes("node1", arr1));  
                root.Nodes.Add(CreateNodes("node2", arr2));  
                root.Nodes.Add(CreateNodes("node3", arr3));  
     
                t.ExpandAllNodes();   
            }  
     
            protected RadTreeNode CreateNodes(string parentName, string[] arr)  
            {  
                RadTreeNode parentNode = new RadTreeNode(parentName);  
                parentNode.ImageUrl = ImageUrl;  
                  
                foreach (string name in arr)  
                {  
                    RadTreeNode node = new RadTreeNode(name);  
                    node.ImageUrl = ImageUrl;  
                    parentNode.Nodes.Add(node);  
                }  
     
                return parentNode;  
            }  
          
        }  
     
    }  
     
  2. Yana
    Admin
    Yana avatar
    4813 posts

    Posted 11 Nov 2008 Link to this post

    Hello Laurentiu,

    You should also set ExpandedImageUrl like this:

    node.set_expandedImageUrl(imageUrl);  

    Kind regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Laurentiu
    Laurentiu avatar
    9 posts
    Member since:
    Oct 2008

    Posted 11 Nov 2008 Link to this post

    Thank you Yana. it runs ok

     

    Llaurentiu

Back to Top