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

Disable all parent nodes

4 Answers 87 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 09 Dec 2008, 11:56 AM
Hi

I've a tree view bound to a database, this is my code, and it works OK.

 

Dim Exp As New clsExpert

 

Dim dt As DataTable = Exp.GetChildByProvider(UserID, ProviderID)

 

If dt.Rows.Count > 0 Then

 

With Me.tvNav

 

.DataSource = dt

.DataFieldID =

"ID"

 

 

.DataFieldParentID ="ParentID"

 

 

.DataTextField = "Node"

 

 

.DataValueField = "ChildID"

 

 

.DataBind()

 

.ExpandAllNodes()

 

End With

 

 

Else

 

 

Me.lblNavStatus.Text = "No Children set up."

 

 

End If

This gives me a 2 level tree, with groups and children. How can I disable the top level nodes to stop users from clicking them and getting an error, as these first level nodes dont have any ID's associated with them.

Andy

 

 

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2008, 12:54 PM
Hi,

Try the following javascript code to prevent selection of the parent node.

JS:
<script type="text/javascript"
function OnClientNodeClicking(sender, eventArgs) 
  var node = eventArgs.get_node();   
 
  if(node.get_nodes().get_count()>0) 
  { 
    eventArgs.set_cancel(true); 
   
   } 
   
  
</script> 


Thanks
Princy.
0
Andy Green
Top achievements
Rank 2
answered on 16 Dec 2008, 10:36 PM
Thanks for reply and appologies for not coming back sooner, battling with RadGrid hierarchy at the moment.

I tried this and disabled all node, not just the top ones.

Andy
0
Veselin Vasilev
Telerik team
answered on 17 Dec 2008, 07:56 AM
Hello Andy Green,

Princy's code should work as expected. It would cancel the OnClientNodeClicking event of all nodes that have children.
What exactly is the behavior that you see?

Sincerely yours,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andy Green
Top achievements
Rank 2
answered on 22 Dec 2008, 10:44 AM
Thanks Princy,

Not sure what I did, but tried it again and it worked first time.

Andy
Tags
TreeView
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Andy Green
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or