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

e.Node.Selected

1 Answer 150 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Iron
Kjell asked on 30 Jan 2013, 12:17 PM
This works great except e.Node.Selected = False
I try disable that you can click (select) on node 1 and 2, but it may not function?
Help me :-)
Protected Sub RadTreeView1_NodeDataBound(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
    e.Node.ToolTip = (TryCast(e.Node.DataItem, DataRowView))("NodeId").ToString() & " + " & (TryCast(e.Node.DataItem, DataRowView))("ParentNodeId").ToString()
    e.Node.ImageUrl = "../images/caTree/" & (TryCast(e.Node.DataItem, DataRowView))("ImageUrl").ToString()
    e.Node.NavigateUrl = "../admin_dbpage.aspx?id=" & (TryCast(e.Node.DataItem, DataRowView))("NodeId").ToString() & "&db=ledare" & "&url=ledare/"
    e.Node.Target = "main"
 
    If (TryCast(e.Node.DataItem, DataRowView))("NodeId").ToString() = 1 Or (TryCast(e.Node.DataItem, DataRowView))("NodeId").ToString() = 2 Then
        e.Node.AllowDrag = False
        e.Node.Selected = False
    End If
 
End Sub

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 01 Feb 2013, 02:54 PM
Hi Kjell,

The selected property of a node can be used in a scenario when you need to have a specific node selected/not selected. I tested the scenario and once you set the selected to false, the node does not get selected on page load. However, as I understand from your scenario you are trying to make the node not selectable. You can use the AllowDrag property of a node if you need to disable the dragging of a specific node of the Enable="false" if you need to disable the node.   Another approach is to cancel the selection and the clicking of the specific node using the client-side approach with the OnClientNodeClicking event:
<telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="WebBlue" OnClientNodeClicking="OnClientNodeClicking" OnNodeDataBound="RadTreeView1_NodeDataBound" EnableDragAndDrop="true">
           </telerik:RadTreeView>

javascript:
function OnClientNodeClicking(sender, args) {
                  if (args.get_node().get_text() == "nameOfTheNode")
                  {
                     //cancel the click event
                      args.set_cancel(true);
                      //prevents selection of a node
                      args.get_node().set_selected(false);
                    
                  }
             }

Greetings,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Kjell
Top achievements
Rank 1
Iron
Answers by
Kate
Telerik team
Share this question
or