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)
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
>.