Am succesfully dragging Listview1 items to Listview2. But I cannot drag to Listview2 if I place it in a Panel. I need the Panel to group a bunch of controls. I have the standard methods as follows, as obtained from a tutorial and it works thus far but not in a Panel of course.
Code:
For Each c As Control In Me.Controls
If TypeOf c Is ListView Then
With CType(c, ListView)
.AllowDrop = True
.FullRowSelect = True
.MultiSelect = False
AddHandler .ItemDrag, AddressOf ListView_ItemDrag
AddHandler .DragEnter, AddressOf ListView_DragEnter
AddHandler .DragDrop, AddressOf ListView_DragDrop
End With
Next
Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs)
If sender Is Nothing OrElse Not TypeOf sender Is ListView Then Exit Sub
With CType(sender, ListView)
.DoDragDrop(e.Item, DragDropEffects.Copy)
End With
End Sub
Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If sender Is Nothing OrElse Not TypeOf sender Is ListView Then Exit Sub
'If this is a listview item then allow the drag
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If sender Is Nothing OrElse Not TypeOf sender Is ListView Then Exit Sub
'Remove the item from the current listview and drop it in the new listview
With CType(sender, ListView)
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
Dim draggedItem As ListViewItem = CType(e.Data.GetData(GetType(ListViewItem)), ListViewItem)
draggedItem.ListView.Items.Remove(draggedItem)
.Items.Add(draggedItem)
End If
End With
End Sub