Drag&Drop from ListView 
Author Message
 Drag&Drop from ListView

Hi!

I'm trying to use drag and drop with a couple of listViews
but with no luck. I first tried with Listboxes and that
worked fine but I haven't managed the same with Listview.

Grateful for any suggestions!
/ Markus

(code below for dragging a listviewitem from lstPlaced to
lstRemaining, lstRemaining has AllowDrop=true)

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

        'Get selected item
        Dim item As ListViewItem
        For Each item In lstPlaced.SelectedItems
            Exit For
        Next
        If Not item Is Nothing Then
            lstPlaced.DoDragDrop(item,DragDropEffects.Move)
        End If
End Sub

Private Sub lstRemaining_DragEnter(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DragEventArgs)

         e.Effect = DragDropEffects.Move

End Sub

    Private Sub lstRemaining_DragDrop(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DragEventArgs)

        Dim item As ListViewItem
        item = CType(e.Data, ListViewItem)

        If Not item Is Nothing Then

            lstRemaining.Items.Add(item)
            lstPlaced.Items.Remove(item)

            'Todo: Update items in db
        End If

    End Sub



Mon, 29 Nov 2004 21:12:11 GMT  
 Drag&Drop from ListView
Here's what you need to do:

1.  Add the "Handles lstRemaining.DragEnter" and "Handles
lstRemaining.DragDrop" to your event handlers below
2.  Get the item being dragged using this:
    item = CType(e.Data.GetData("System.Windows.Forms.ListViewItem"),
ListViewItem)

You can paste the link below into the Visual Studio. Net Help URL  for more
info on the DragEventArgs.Data property.  Basically, many things can be
dragged into the ListView object, so you have to get the data format that
you need.
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsdrageventargsc
lassdatatopic.htm

3.  Reverse the adding and inserting order since the item needs to be
removed first and then added to the destination

Hope this helps!

Tania Means
VB QA

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hi!

> I'm trying to use drag and drop with a couple of listViews
> but with no luck. I first tried with Listboxes and that
> worked fine but I haven't managed the same with Listview.

> Grateful for any suggestions!
> / Markus

> (code below for dragging a listviewitem from lstPlaced to
> lstRemaining, lstRemaining has AllowDrop=true)

> Private Sub lstPlaced_ItemDrag(ByVal sender As Object,
> ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles
> lstPlaced.ItemDrag

>         'Get selected item
>         Dim item As ListViewItem
>         For Each item In lstPlaced.SelectedItems
>             Exit For
>         Next
>         If Not item Is Nothing Then
>             lstPlaced.DoDragDrop(item,DragDropEffects.Move)
>         End If
> End Sub

> Private Sub lstRemaining_DragEnter(ByVal sender As
> System.Object, ByVal e As
> System.Windows.Forms.DragEventArgs)

>          e.Effect = DragDropEffects.Move

> End Sub

>     Private Sub lstRemaining_DragDrop(ByVal sender As
> System.Object, ByVal e As
> System.Windows.Forms.DragEventArgs)

>         Dim item As ListViewItem
>         item = CType(e.Data, ListViewItem)

>         If Not item Is Nothing Then

>             lstRemaining.Items.Add(item)
>             lstPlaced.Items.Remove(item)

>             'Todo: Update items in db
>         End If

>     End Sub



Tue, 30 Nov 2004 04:06:19 GMT  
 Drag&Drop from ListView
Thanks for your help, it worked wonders!

But I also tried creating a ListViewItem of my own and am
trying to drag and drop this object instead, without any
luck. Adding items work fine and it seems like dragging
also works but not the droping part.

I suspect I'm doing something wrong in
the "e.Data.GetData"-part...

Grateful for any help!
/ Markus

(dragging from lstPlaced to lstRemaining)

Private Class GoodsListViewItem
   Inherits ListViewItem

   Public m_Goods As Goods

   Sub New(ByVal pGoods As Goods)
       MyBase.New(pGoods.Id.ToString)
       m_Goods = pGoods
   End Sub
End Class

Private Sub lstPlaced_ItemDrag(ByVal sender As Object,
ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles
lstPlaced.ItemDrag
   'Get selected item
   Dim item As GoodsListViewItem
   For Each item In lstPlaced.SelectedItems
       Exit For
   Next
   If Not item Is Nothing Then
       lstPlaced.DoDragDrop(item, DragDropEffects.Move)
   End If
End Sub

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

    Dim item As GoodsListViewItem
    item = CType(e.Data.GetData
("System.Windows.Forms.ListViewItem"), GoodsListViewItem)

    If Not item Is Nothing Then
       'Update items in db & move
       MoveGoods(item, m_CurrentLoad, lstPlaced,
lstRemaining)
    End If
End Sub

Quote:
>-----Original Message-----
>Here's what you need to do:

>1.  Add the "Handles lstRemaining.DragEnter" and "Handles
>lstRemaining.DragDrop" to your event handlers below
>2.  Get the item being dragged using this:
>    item = CType(e.Data.GetData

("System.Windows.Forms.ListViewItem"),
Quote:
>ListViewItem)

>You can paste the link below into the Visual Studio. Net
Help URL  for more
>info on the DragEventArgs.Data property.  Basically, many
things can be
>dragged into the ListView object, so you have to get the
data format that
>you need.
>ms-

help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsforms
drageventargsc
Quote:
>lassdatatopic.htm

>3.  Reverse the adding and inserting order since the item
needs to be
>removed first and then added to the destination

>Hope this helps!

>Tania Means
>VB QA

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.



>> Hi!

>> I'm trying to use drag and drop with a couple of
listViews
>> but with no luck. I first tried with Listboxes and that
>> worked fine but I haven't managed the same with
Listview.

>> Grateful for any suggestions!
>> / Markus

>> (code below for dragging a listviewitem from lstPlaced
to
>> lstRemaining, lstRemaining has AllowDrop=true)

>> Private Sub lstPlaced_ItemDrag(ByVal sender As Object,
>> ByVal e As System.Windows.Forms.ItemDragEventArgs)
Handles
>> lstPlaced.ItemDrag

>>         'Get selected item
>>         Dim item As ListViewItem
>>         For Each item In lstPlaced.SelectedItems
>>             Exit For
>>         Next
>>         If Not item Is Nothing Then
>>             lstPlaced.DoDragDrop

(item,DragDropEffects.Move)

- Show quoted text -

Quote:
>>         End If
>> End Sub

>> Private Sub lstRemaining_DragEnter(ByVal sender As
>> System.Object, ByVal e As
>> System.Windows.Forms.DragEventArgs)

>>          e.Effect = DragDropEffects.Move

>> End Sub

>>     Private Sub lstRemaining_DragDrop(ByVal sender As
>> System.Object, ByVal e As
>> System.Windows.Forms.DragEventArgs)

>>         Dim item As ListViewItem
>>         item = CType(e.Data, ListViewItem)

>>         If Not item Is Nothing Then

>>             lstRemaining.Items.Add(item)
>>             lstPlaced.Items.Remove(item)

>>             'Todo: Update items in db
>>         End If

>>     End Sub

>.



Sat, 04 Dec 2004 04:35:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Drag-&-drop in listview control??

2. Drag &Drop using listView Controls

3. TreeView + ListView +Drag&Drop

4. Subject: ListView Drag & Drop Re-order

5. Listview drag & Drop

6. Drag & Drop in Listviews

7. Q:drag/drop & columns on ListView

8. Listview drag & drop

9. Drag & drop action within ListView and Treeview

10. Drag from ListView & Drop in TreeView controls

11. Listview drag & drop

12. Drag & Drop Listview

 

 
Powered by phpBB® Forum Software