CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    Drag-Drop from one Listbox to another

    Can you tell me how to implement Drag-Drop between 2 listboxes?

    I want to drag an item from one listbox and drop it into another..

    Thanx..


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Drag-Drop from one Listbox to another

    Here's an example I threw together to demonstrate Dragging Items between Listboxes:'Add 2 Listboxes to a Form...
    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: http://www.allexperts.com/displayExp...p?Expert=11884
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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

Featured