Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > How to remove + symbols and lines
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Answered How to remove + symbols and lines

Feed from this thread
  • Posted on May 30, 2008 (permalink)

    Hi all,

    I am new to the RadControls suite so forgive me if this is a daft question!  I want to have the tree-view displayed with no lines or + signs, but instead showing just the text of the node, which can then be clicked to expand/collapse (ideally with child nodes slightly indented from their parents).  The effect I'm trying to achieve is shown in the left-hand nav of http://ninetwoseven.com/psa/withoutMenu/gateway.html#.  I have set SingleExpandPath="true" and ShowLineImages="false" but am unsure about how to remove the + signs and make the nodes clickable instead.

    What is the best way to do this?  Should I make a custom skin (to remove the lines and + symbols) and then write a Javascript function to handle the OnClientNodeClicked event and expand/collapse the selected node?  Or is there a neater way?

    All answers very gratefully received!

    Ed Graham

  • Answer Simon Simon admin's avatar

    Posted on Jun 2, 2008 (permalink)

    Hello Ed,

    Plus and Minus signs could be removed either with CSS or with JavaScript. The former approach would only work in IE7, FireFox, Opera and Safari. IE6, on the other hand does not support the needed selectors.

    In any case, here is the CSS code:

            img[class='8'
            { 
                visibilityhidden !important; 
            } 
             
            div > img:first-child 
            { 
                displaynone !important; 
            } 

    Here is the JavaScript code for the second approach:

            function hideTreeViewImages() 
            { 
                var tree = <%= RadTreeView1.ClientID %>; 
                var treeViewDiv = document.getElementById(tree.ID); 
                 
                var childDivs = treeViewDiv.childNodes; 
                var childDivsCount = childDivs.length; 
                 
                //Iterate through all child divs of the main TreeView div. 
                for (var childDivIndex = 0; childDivIndex < childDivsCount; childDivIndex++) 
                { 
                    var childDiv = childDivs[childDivIndex]; 
                     
                    var images = childDiv .getElementsByTagName("IMG"); 
                    var imagesCount = images.length; 
                     
                    //Iterate through all img elements of the current Node's corresponding div. 
                    for (var imageIndex = 0; imageIndex < imagesCount; imageIndex++) 
                    { 
                        var image = images[imageIndex]; 
                         
                        if (image.className == "8"
                        { 
                            //Hide img elements with class attribute set to "8" 
                            //(these are Plus/Minus images of the TreeView). 
                            image.style.display = "none"
                        } 
                    } 
                } 
            } 
             
            //Hide images upon page load. 
            window.onload = hideTreeViewImages; 
             
            //Handles the BeforeClientClick event of the RadTreeView: 
            //  -- the Node is toggled; 
            //  -- if the Node has child Nodes, its previously expanded sibling is collapsed. 
            function BeforeClientClick(node) 
            { 
                node.Toggle(); 
                 
                if (node.Nodes.length > 0) 
                { 
                    CollapseExpandedSibling(node); 
                } 
            } 
             
            //Collapse the already expanded siblings of a Node. 
            function CollapseExpandedSibling(node) 
            { 
                //Gets the correct parent of the Node - it's either another Node or the TreeView. 
                var parent = node.Parent; 
                 
                if (parent == null
                { 
                    parent = node.TreeView; 
                } 
                 
                var siblings = parent.Nodes; 
                var siblingsCount = siblings.length; 
                 
                //Iterate through all sibling Nodes until an expanded one is found. 
                for (var nodeIndex = 0; nodeIndex < siblingsCount; nodeIndex++) 
                { 
                    var siblingNode = siblings[nodeIndex]; 
                     
                    if ((siblingNode != node) && 
                        (siblingNode.Expanded)) 
                    { 
                        //Collapse the expanded sibling Node and exit the function. 
                        siblingNode.Collapse(); 
                         
                        return
                    } 
                } 
            } 

    In summary, upon page load the images of the TreeView are hidden. The BeforeClientClick event is handled - the clicked Node is expanded and the previously expanded sibling of the clicked Node is collapsed.

    I hope this helps.

    Best wishes,
    Simon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Posted on Jun 3, 2008 (permalink)

    Thanks very much indeed, Simon -- that is just what I needed!

  • Simon Simon admin's avatar

    Posted on Jun 3, 2008 (permalink)

    Hello Ed,

    I am glad that you found this useful.

    Soon, two articles will be added to our Help for both RadTreeView for ASP.NET and RadTreeView for ASP.NET AJAX:
    1. Hiding all RadTreeView structure images: Lines, Minus and Plus signs;
    2. Expanding only one Node per level
    So, if anyone else is interested, feel free to check them out when they are live (later this week).

    Greetings,
    Simon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Rick avatar

    Posted on Apr 4, 2011 (permalink)

    Is there a way to do this on the server side?

  • Peter Peter admin's avatar

    Posted on Apr 8, 2011 (permalink)

    Hi Rick,

    This is not achievable server side.

    Regards,
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > How to remove + symbols and lines