Max Level Depth

4 posts, 0 answers
  1. Andreas Karpinski
    Andreas Karpinski avatar
    8 posts
    Member since:
    Sep 2009

    Posted 02 Dec 2009 Link to this post

    Hi,
    is there any way to set a max Level for the Treeview?
    I just want to allow 3 Level Main Node -> Nodes -> Subnodes and not further! Because in my case it wont be used so i need a way to disable or block adding a "SubSubNode".

    So it should look like this:

    Main Node
     |_Node 1
     | |_Subnode 1
     | |_Subnode 2
     | |_Subnode 3
     |_Node 1
     | |_Subnode 1
     |_Node 1
      |_Subnode 1
       |_Subnode 2

    And not like:

    Main Node
     |_Node 1
     | |_Subnode 1
     | | |_SubSubnode 1
     | | |_SubSubnode 2
     | |_Subnode 2
     | |_Subnode 3
     |_Node 1
     | |_Subnode 1
     |_Node 1
      |_Subnode 1
       |_Subnode 2

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Dec 2009 Link to this post

    Hello Andreas,

    You can check the level of the node and based on that, you can either add or prevent adding node. Here is the example that I tried from client.

    javscript:
     
    <script type="text/javascript"
        function Button1_onclick() { 
            var tree = $find('<%= RadTreeView1.ClientID %>'); 
            var node = tree.findNodeByText('SubNode 1'); 
            if (node.get_level() < 2) {  // Here check for level before adding the node, index starts from 0 
                // add the node 
            } 
            else { 
                alert("Cannot add child nodes"); 
            } 
        } 
    </script> 

    And here is the equivalent server side cod for checking the level before adding the node.
    CS:
     
    protected void RadTreeView1_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
        { 
            RadTreeNode node = (RadTreeNode)e.Node; 
            if (node.Level < 2) 
            { 
                // add node 
            }         
        } 

    -Shinu.
  3. Andreas Karpinski
    Andreas Karpinski avatar
    8 posts
    Member since:
    Sep 2009

    Posted 04 Dec 2009 Link to this post

    So there is no build in feature ?

    But anyway your solution works!
    Thank you!


    Now i 've go another question.

    Is there anyway to disable an item out of the RadTreeViewContextMenu?

    So i can disable the "Create Node" button on Level > 2

  4. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 07 Dec 2009 Link to this post

    I believe for the context menu functionality you can read over the sample code provided in this article, it should help you out with your implementation :)
Back to Top