Results 1 to 2 of 2

Thread: drag and drop inside treeview.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    drag and drop inside treeview.

    Hi,

    I´ve got my treeviews working, so that tv1 fills up from a db table when the form loads. When I drag items from that tv and drop them in another tv, the item moves and the database updates fine.

    However, now I would like to also be able to rearrange the order in the second tv by a drag and drop operation. Is this possible?

    Fuga.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    Re: drag and drop inside treeview.

    sorry, here´s the code I use (got it from here I think)

    Code:
        Private Sub treeView1_ItemDrag(ByVal sender As Object, ByVal e As ItemDragEventArgs) Handles TreeView1.ItemDrag
            DoDragDrop(e.Item, DragDropEffects.All)
        End Sub
    Code:
        Private Sub treeView2_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles TreeView2.DragOve
            Dim targetPoint As Point = TreeView2.PointToClient(New Point(e.X, e.Y))
            e.Effect = e.AllowedEffect
    
            TreeView2.SelectedNode = TreeView2.GetNodeAt(targetPoint)
        End Sub
    Code:
        Private Sub treeView2_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TreeView2.DragDrop
            Dim targetPoint As Point = TreeView2.PointToClient(New Point(e.X, e.Y))
            Dim targetNode As TreeNode = TreeView2.GetNodeAt(targetPoint)
            Dim draggedNode As TreeNode = CType(e.Data.GetData(GetType
            If targetNode Is Nothing Then
                TreeView2.Nodes.Add(draggedNode)
            Else
                TreeView2.Nodes.Insert(targetNode.Index, draggedNode)
            End If
        End Sub
    Thanks!

    Fuga.

    Never mind. I figured it out! I had some database stuff in the code that didnt work.
    Last edited by Fuga; Nov 22nd, 2007 at 03:15 PM. Reason: thread resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width