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

Max Level Depth

3 Answers 164 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andreas Karpinski
Top achievements
Rank 1
Andreas Karpinski asked on 02 Dec 2009, 09:14 PM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Dec 2009, 06:44 AM
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.
0
Andreas Karpinski
Top achievements
Rank 1
answered on 04 Dec 2009, 09:11 AM
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

0
Schlurk
Top achievements
Rank 2
answered on 07 Dec 2009, 09:37 PM
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 :)
Tags
TreeView
Asked by
Andreas Karpinski
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Andreas Karpinski
Top achievements
Rank 1
Schlurk
Top achievements
Rank 2
Share this question
or