Results 1 to 3 of 3

Thread: drag and drop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127

    Post

    I have a form with 2 list boxes.
    I am trying to drag an item from one list box to a nother.
    I can't figure out what events or methods to use.
    Any suggestions???
    Thanks.
    Danny.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's an Example I've put together for you:
    Code:
    Private Sub Form_Load()
        Dim iIndex As Integer
        
        List1.DragMode = vbManual
        List2.DragMode = vbManual
        List1.DragIcon = LoadPicture("..\Common\Graphics\Icons\DragDrop\Drag1pg.ico")
        List2.DragIcon = LoadPicture("..\Common\Graphics\Icons\DragDrop\Drag1pg.ico")
        For iIndex = 1 To 10
            List1.AddItem "Item " & Right$("00" & iIndex, 2)
        Next
    End Sub
    
    Private Sub List1_DragDrop(Source As Control, X As Single, Y As Single)
        If TypeOf Source Is ListBox Then
            If Source.Name = "List1" Then Exit Sub
            List1.AddItem Source
            Source.RemoveItem Source.ListIndex
        End If
    End Sub
    
    Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If List1.ListIndex < 0 Then Exit Sub
        If Button = vbLeftButton Then List1.Drag vbBeginDrag
    End Sub
    
    Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then List1.Drag vbEndDrag
    End Sub
    
    Private Sub List2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If List2.ListIndex < 0 Then Exit Sub
        If Button = vbLeftButton Then List2.Drag vbBeginDrag
    End Sub
    
    Private Sub List2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then List2.Drag vbEndDrag
    End Sub
    
    Private Sub List2_DragDrop(Source As Control, X As Single, Y As Single)
        If TypeOf Source Is ListBox Then
            If Source.Name = "List2" Then Exit Sub
            List2.AddItem Source
            Source.RemoveItem Source.ListIndex
        End If
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127

    Post

    once again Aaron
    YOU SAVED THE DAY ! ! ! !
    Thanks
    Danny.

Posting Permissions

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



Click Here to Expand Forum to Full Width