PDA

View Full Version : Drag and Drop between ListViews



lifeson
11-07-2008, 01:23 AM
How do I drag and drop items between 2 listview controls?

I can drop the selected item into a text box but not into the listview


I want to drag from lvwEntitlements and drop the item onto lvwApplied.

I think this gets the item text from the lvwEntitlements (dragMode is set to automatic)

Private Sub lvwEntitlements_ItemClick(ByVal Item As MSComctlLib.ListItem)
Set MyDataObj = New DataObject
MyDataObj.SetText Item

End Sub

and this is the closest I could find to drop the item
(dropmode is set to manual)
Private Sub lvwApplied_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Data.GetText

End Sub

lifeson
11-07-2008, 02:00 AM
This seems to work with no need to create a data object :yes

Private Sub lvwApplied_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
With lvwApplied
.ListItems.Add , , lvwEntitlements.SelectedItem.Text
End With

End Sub

lifeson
11-07-2008, 02:03 AM
This seems to work, but it doesnt remove the item from the original list

Private Sub lvwApplied_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
With lvwApplied
.ListItems.Add , , lvwEntitlements.SelectedItem.Text
End With

End Sub

georgiboy
11-07-2008, 02:08 AM
Have you got an example file to play with?

lifeson
11-07-2008, 02:19 AM
here you go

georgiboy
11-07-2008, 02:24 AM
Is this any help

http://www.vbaexpress.com/forum/showthread.php?t=454


It may just be me but i could not see any listviews in the demo file

lifeson
11-07-2008, 03:07 AM
sorry the list views are on a user form.

lifeson
11-07-2008, 06:31 AM
Is this any help

http://www.vbaexpress.com/forum/showthread.php?t=454


It may just be me but i could not see any listviews in the demo file

That was the thread i looked at first of all which started me to look at data objects, but I got lost

GTO
11-07-2008, 06:31 PM
Greetings lifeson,

Reference:


This seems to work, but it doesnt remove the item from the original list...

This seems to work:

Private Sub lvwApplied_OLEDragDrop(Data As MSComctlLib.DataObject, _
Effect As Long, Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)

Dim cnt As Long

With lvwApplied
cnt = .ListItems.Count + 1
.SmallIcons = UserForm1.imgSnooker
.ListItems.Add , , lvwEntitlements.SelectedItem.Text, , cnt
End With

lvwEntitlements.ListItems.Remove lvwEntitlements.SelectedItem.Index

End Sub

Hope this helps :) ,

Mark

PS - Just a thought, but for those of us with less than stellar screen size, a line-break or two keeps the vba window from pushing out the edge and makes it a lot easier to read.

lifeson
11-08-2008, 12:14 PM
Mark

PS - Just a thought, but for those of us with less than stellar screen size, a line-break or two keeps the vba window from pushing out the edge and makes it a lot easier to read.

:oops: :oops:

Thanks for the code though Mark.

GTO
11-08-2008, 12:52 PM
You bet and happy to help.

I have never used a list view ctrl, but liked the "looks".:thumb