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

Disable Collapse in TreeView

6 Answers 267 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
piro
Top achievements
Rank 1
piro asked on 26 Dec 2008, 03:34 AM
I want to disable collapse property went click a node on tree view. How can't i do it?

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Dec 2008, 08:38 AM
Hi,

Try the following code snippet to achieve the desired scenario.


ASPX:
<telerik:RadTreeView ID="RadTreeView1" OnClientNodeCollapsing="OnClientNodeCollapsing"      runat="server"  > 
          

JS:
<script type="text/javascript"
function OnClientNodeCollapsing(sender, eventArgs) 
var node = eventArgs.get_node(); 
 eventArgs.set_cancel(true); 
</script> 



Shinu
0
John Davis
Top achievements
Rank 2
answered on 22 Mar 2009, 02:32 PM
This is very useful code.  How can we modify it to disable collapse for only the top (first) node?
0
Yana
Telerik team
answered on 23 Mar 2009, 07:11 AM
Hello John,

Please modify the js function like this:

<script type="text/javascript">    
function OnClientNodeCollapsing(sender, eventArgs)    
{    
   var node = eventArgs.get_node();    
   if(node.get_level() == 0)  
     eventArgs.set_cancel(true);    
}    
</script>    
 

Kind regards,
Yana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
John Davis
Top achievements
Rank 2
answered on 23 Mar 2009, 01:40 PM
Yana,
It works great, thank you. 

This technique could help others who posted questions about how to change font from subdued to normal when a node is disabled.  You can enable a node to achieve normal font display, then use this code to simulate a disabled node.

Steve
0
Edward
Top achievements
Rank 1
answered on 29 Jul 2009, 04:11 PM
Hi,

In my current project I have the need to show the root node, but make it so that it can't be collapsed.  This fix gets my partially there, but usability testing shows that it would be better to have a way of not showing the collapse icon at all. Is there any way to hide the [-] (minus sign in my case), so that users don't get confused?  It would also give me additional real estate on the left side.

So this:

[-] Root Node
.......|-- [+] Next Level

would become:

Root Node
...|-- [+] Next Level


I have seen the posts that suggest change the display style to 'none' on the toggle element.  I sort of see that as a hack and was hoping there was a better, cleaner way of geeting the result above. That fix also doesn't gain the space back from where the toggle and line are.


Thanks,
Ed R.
0
Yana
Telerik team
answered on 30 Jul 2009, 10:44 AM
Hi Edward,

Unfortunately setting display to "none" to the toggle element is the only way to remove it.

Greetings,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
piro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John Davis
Top achievements
Rank 2
Yana
Telerik team
Edward
Top achievements
Rank 1
Share this question
or