Consulting

Results 1 to 11 of 11

Thread: Drag and Drop between ListViews

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Drag and Drop between ListViews

    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)

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

    End Sub[/VBA]

    and this is the closest I could find to drop the item
    (dropmode is set to manual)
    [VBA]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[/VBA]

  2. #2
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    This seems to work with no need to create a data object

    [VBA]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[/VBA]

  3. #3
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    This seems to work, but it doesnt remove the item from the original list

    [VBA]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[/VBA]

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,202
    Location
    Have you got an example file to play with?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2404, Build 17531.20128

  5. #5
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    here you go

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,202
    Location
    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
    Last edited by georgiboy; 11-07-2008 at 02:35 AM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2404, Build 17531.20128

  7. #7
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    sorry the list views are on a user form.

  8. #8
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Quote Originally Posted by georgiboy
    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

  9. #9
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings lifeson,

    Reference:

    Quote Originally Posted by lifeson
    This seems to work, but it doesnt remove the item from the original list...
    This seems to work:

    [vba]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[/vba]

    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.

  10. #10
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Quote Originally Posted by GTO

    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.


    Thanks for the code though Mark.

  11. #11
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You bet and happy to help.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •