Forum  Commercial Foru...  Commercial Foru...  Drag & Drop Treeview To Itself Folders Below
Previous Previous
 
Next Next
New Post 11/30/2009 8:04 PM
Unresolved
  derekmhart@yahoo.com
761 posts
1st Level Poster


Drag & Drop Treeview To Itself Folders Below 
Modified By derekmhart@yahoo.com  on 12/1/2009 12:05:57 AM)

I am using this code to drag and drop a treeview node to a different place on the same treeview. To my surprise, if I drag a node to a child node of the same node, it completely freezes on this line, because it removes itself. Where in the code can I detect if I am dragging a node onto a child of itself. Does not work!
            NewParent.Nodes.Add(NodeToMove)

 Full Code:

    Private Sub TreeVault_DragDrop(ByVal sender As Object, ByVal e As Gizmox.WebGUI.Forms.DragEventArgs) Handles TreeVault.DragDrop

        Dim sql As String

            If e.GetType Is GetType(DragDropEventArgs) Then

                Dim dd As DragDropEventArgs = e

 

                If dd.Source IsNot Nothing _

                    AndAlso dd.SourceMember IsNot Nothing _

                    AndAlso dd.Source.GetType() Is GetType(Gizmox.WebGUI.Forms.TreeView) _

                    AndAlso dd.SourceMember.GetType() Is GetType(Gizmox.WebGUI.Forms.TreeNode) Then

                    Dim tn As TreeNode = dd.SourceMember

                    If dd.TargetMember IsNot Nothing And tn IsNot dd.TargetMember Then

                        MoveTreeNode(tn, dd.TargetMember)

                    End If

                    VaultFileTreeSet()

                End If

            End If

    End Sub

 

    Private Sub MoveTreeNode(ByVal NodeToMove As TreeNode, ByVal NewParent As TreeNode)

            NodeToMove.Remove()

            NewParent.Nodes.Add(NodeToMove)

            TreeVault.Sort()

            NewParent.Expand()

    End Sub

 

 

 
New Post 12/1/2009 8:35 AM
  palli
14307 posts
1st Level Poster




Re: Drag & Drop Treeview To Itself Folders Below 

Hi Derek,

Actually, that isn't a surprise, considering the logic in the MoveTreeNode. If you drag a node to the child of the same node, you first delete, or more precisely remove, the parent node from the tree, and then try to add it to a subnode, which is no longer in the tree.

I would place a check on this in the MoveTreeNode itself. You simple traverse the tree from NewParent and up the tree via the NewParent.Parent property. If you reach the NodeToMove, you know the new parent is a subnode of the node you are moving and that's where you have a special case.

When you do have that case, you will have to decide on a logic how to handle the move, or simply cancel the move.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  Drag & Drop Treeview To Itself Folders Below
.NET HTML5 Web, Cloud and Mobile application delivery | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2012 Visual WebGui®       Visual WebGui weblog on ASP.NET Gizmox Blog Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS