
Drag and Drop to a Listview
Hi Peter,
We tried this and run into problems at first too ;) The issue for us was
that we tried to add the drop Data object to the second ListView before
either deleting or cloning it from the first ListView. The ListView
collection requires unque objects to be added to the collection. If you
catch the exceptions on the DoDragDrop, you will get insight into the actual
problem.
Here is a working sample:
Private Sub ListView1_ItemDrag(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
ListView1.DoDragDrop(e.Item, DragDropEffects.Copy)
End Sub
Private Sub ListView2_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView2.DragEnter
If (e.Data.GetDataPresent(DataFormats.Serializable)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListView2_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView2.DragDrop
Dim item As ListViewItem
Try
item = e.Data.GetData(GetType(ListViewItem))
ListView2.Items.Add(item.Clone)
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Hope this helps. Regards,
Vladimir Sadov and Paul Yuknewicz
Visual Basic .NET Team
MS Co.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Quote:
> Hi NG
> I try to drag a Listview entry to another Listview.
> The Drop Listview contains at the moment of the Drop NO Items..
> How can I add one Item in this Drop-Event ?
> Droping to other Controls is no Problem (ie. Textboxes)
> But it i have no idea how to use Drag'n Drop in my Case.........
> Any Help is welcome !
> Regards
> Peter