Drag and Drop to a Listview 
Author Message
 Drag and Drop to a Listview

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




Tue, 21 Dec 2004 15:20:56 GMT  
 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





Wed, 22 Dec 2004 04:54:32 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. implement drag and drop between two listviews

2. Dragging and Dropping using a Listview

3. Drag and Drop in a ListView help please?

4. sample code for allowing drag and drop of multiple listview selections?

5. I Dont get the Listview drag and drop model

6. Drag and drop in ListView Control

7. drag and drop between listview and treeview

8. Drag&Drop from ListView

9. TreeView + ListView +Drag&Drop

10. Subject: ListView Drag & Drop Re-order

11. ListView and Drag and Drop

12. OLE drag and drop in listview control

 

 
Powered by phpBB® Forum Software