
Imports System.Data
Imports System.Drawing
Imports Telerik.Web.UI

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            BindToDataTable(RadTreeView1)
        End If
    End Sub

    Private Function GetDataSource() As DataTable
        Dim dataTable As DataTable = New DataTable()
        Dim column As DataColumn = New DataColumn()
        column.DataType = Type.[GetType]("System.Int32")
        column.ColumnName = "OrderID"
        dataTable.Columns.Add(column)

        column = New DataColumn()
        column.DataType = Type.[GetType]("System.String")
        column.ColumnName = "ShipName"
        dataTable.Columns.Add(column)

        Dim PrimaryKeyColumns As DataColumn() = New DataColumn(0) {}
        PrimaryKeyColumns(0) = dataTable.Columns("OrderID")
        dataTable.PrimaryKey = PrimaryKeyColumns

        For i As Integer = 0 To 8
            Dim row As DataRow = dataTable.NewRow()
            row("OrderID") = i + 1
            row("ShipName") = "Name " & (i + 1)
            dataTable.Rows.Add(row)
        Next

        Return dataTable
    End Function

    Private Sub BindToDataTable(ByVal treeView As RadTreeView)
        treeView.DataTextField = "ShipName"
        treeView.DataFieldID = "OrderID"
        treeView.DataValueField = "OrderID"
        treeView.DataSource = GetDataSource()
        treeView.DataBind()
    End Sub

    Protected Sub RadTreeView1_NodeDataBound(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
        e.Node.ToolTip = "Node Tooltip"
        e.Node.ImageUrl = "https://placeimg.com/32/32/any"
        e.Node.ForeColor = Color.Black

        If Integer.Parse(e.Node.Value) < 4 Then
            e.Node.AllowDrag = False
            e.Node.Selected = False
        Else
            e.Node.NavigateUrl = "google.com"
            e.Node.Target = "_blank"
        End If
    End Sub

    Protected Sub RadTreeView1_NodeDrop(ByVal sender As Object, ByVal e As RadTreeNodeDragDropEventArgs)
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "scr", "window.location.replace('start.aspx');", True)
        BindToDataTable(RadTreeView1)
    End Sub

End Class
