e.SourceDragNode is Nothing

4 posts, 0 answers
  1. çağlar
    çağlar avatar
    2 posts
    Member since:
    Mar 2009

    Posted 11 Sep 2013 Link to this post

    Hi,

    I'm using RadTreeView(Q2 2013 SP1) control with templated nodes. My aspx page is like that;

    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
        
            <telerik:RadTreeView ID="RadTreeView1" Runat="server" EnableDragAndDrop="True" 
                EnableDragAndDropBetweenNodes="True" OnNodeDrop="RadTreeView1_HandleDrop" EnableViewState="false">
                <Nodes>
                    <telerik:RadTreeNode runat="server" Text="Genel Müdür A">
                        <Nodes>
                            <telerik:RadTreeNode runat="server" Text="Genel Müdür Yardımcısı A" >
                            <NodeTemplate>
                                <table>
                                    <tr>
                                        <td>
                                            <asp:Label ID="Label1" runat="server" Text="isim"></asp:Label></td>
                                        <td>
                                            <telerik:RadTextBox ID="RadTextBox1" runat="server">
                                            </telerik:RadTextBox></td>
                                    </tr>
                                </table>
                            </NodeTemplate>
                            </telerik:RadTreeNode>
                        </Nodes>
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode runat="server" Text="Genel Müdür B">
                        <Nodes>
                            <telerik:RadTreeNode runat="server" Text="Genel Müdür Yardımcısı B" >
                            <NodeTemplate>
                                <table>
                                    <tr>
                                        <td>
                                            <asp:Label ID="Label1" runat="server" Text="isim"></asp:Label></td>
                                        <td>
                                            <telerik:RadTextBox ID="RadTextBox1" runat="server">
                                            </telerik:RadTextBox></td>
                                    </tr>
                                </table>
                            </NodeTemplate>
                            </telerik:RadTreeNode>
                        </Nodes>
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeView>
        
        </div>
        </form>
    </body> 

    and also aspx.vb is;

    Protected Sub RadTreeView1_HandleDrop(ByVal sender As Object, ByVal e As RadTreeNodeDragDropEventArgs)
            Dim sourceNode As RadTreeNode = e.SourceDragNode
            Dim destNode As RadTreeNode = e.DestDragNode
            Dim dropPosition As RadTreeViewDropPosition = e.DropPosition

            If destNode IsNot Nothing Then
                'drag&drop is performed between trees

                'dropped node will be a sibling of the destination node
                If sourceNode.TreeView.SelectedNodes.Count <= 1 Then
                    PerformDragAndDrop(dropPosition, sourceNode, destNode)
                ElseIf sourceNode.TreeView.SelectedNodes.Count > 1 Then
                    For Each node As RadTreeNode In RadTreeView1.SelectedNodes
                        If Not node.IsAncestorOf(destNode) Then
                            PerformDragAndDrop(dropPosition, sourceNode, destNode)
                        End If
                    Next
                End If


                destNode.Expanded = True
                sourceNode.TreeView.UnselectAllNodes()
                RadTreeView1.DataBind()

            End If
        End Sub

        Private Shared Sub PerformDragAndDrop(ByVal dropPosition As RadTreeViewDropPosition, ByVal sourceNode As RadTreeNode, ByVal destNode As RadTreeNode)
            If sourceNode.Equals(destNode) OrElse sourceNode.IsAncestorOf(destNode) Then
                Return
            End If
            sourceNode.Owner.Nodes.Remove(sourceNode)

            Select Case dropPosition
                Case RadTreeViewDropPosition.Over
                    ' child
                    If Not sourceNode.IsAncestorOf(destNode) Then
                        destNode.Nodes.Add(sourceNode)
                    End If
                    Exit Select

                Case RadTreeViewDropPosition.Above
                    ' sibling - above                         
                    destNode.InsertBefore(sourceNode)
                    Exit Select

                Case RadTreeViewDropPosition.Below
                    ' sibling - below
                    destNode.InsertAfter(sourceNode)
                    Exit Select
            End Select
        End Sub

    I'm trying to drag and drop templated nodes but in my first try it looses the template controls' values and at the second time i got the error message-  e.SourceDragNode is Nothing.

    please help..
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 16 Sep 2013 Link to this post

    Hi,

    Please try calling the RadTreeView's DataBind() method at the end of the TreeDrop handler and let me know if this helps.

    Regards,
    Kate
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. çağlar
    çağlar avatar
    2 posts
    Member since:
    Mar 2009

    Posted 16 Sep 2013 Link to this post

    Hi Kate,

    I'm also callind RadTreeView DataBind() method at the end of HandleDrop but it doesn't work.

    do you have any other solution ?

    thanks
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 23 Sep 2013 Link to this post

    Hello çağlar,

    I noticed that you also opened a support ticket that I have just answered. I will also paste my reply in this post in case anyone else is looking for a similar solution.  Below you can find a very detailed forum post where you can find very good explanation on the issue that you currently encounter - Drag and drop in RadTreeView replaces template with text.

    Regards,
    Kate
    Telerik
    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 the blog feed now.
Back to Top