views:

36

answers:

1

I'm trying to drag an item between two Groups in the same ListView called 'listTasks'.

Private Sub listTasks_ItemDrag(ByVal sender As Object, ByVal e As ItemDragEventArgs) Handles listTasks.ItemDrag
    listTasks.DoDragDrop(listTasks.SelectedItems, DragDropEffects.Move)
End Sub

Private Sub listTasks_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles listTasks.DragEnter
    e.Effect = DragDropEffects.Move
End Sub

Private Sub listTasks_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles listTasks.DragDrop
    ' how do I tell what group is being dropped into?
End Sub

(note that listTasks_DragEnter ignores DataFormat checks to simplify example)

With listTasks.PointToClient(New Point(e.X, e.Y)) you could use listTasks.GetItemAt(p.X, p.Y) to get the ListView item you're over. Is there something like this for Groups? Or perhaps a better way to determine what group is the target of a drag-drop?

A: 

You can try something like this :

Private lviDraggedItem As ListViewItem

Private Sub ListView1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
    e.Effect = DragDropEffects.Move
End Sub

Private Sub ListView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop

    Dim htInfo As ListViewHitTestInfo = ListView1.HitTest(ListView1.PointToClient(New Point(e.X, e.Y)))

    Dim lviSibling As ListViewItem = htInfo.Item

    Dim lvgGroup As ListViewGroup = lviSibling.Group

    lvgGroup.Items.Add(lviDraggedItem)

    lviDraggedItem = Nothing


End Sub

Private Sub ListView1_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag

    lviDraggedItem = e.Item
    ListView1.DoDragDrop(ListView1.SelectedItems, DragDropEffects.Move)


End Sub

You will probably want to do some more work to place it at a specific place in the group, but this should get you started.

Tony Abrams