Results 1 to 4 of 4

Thread: moving listbox items w/ mouse

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    i live where you don't
    Posts
    76

    moving listbox items w/ mouse

    does anyone know how to shift listbox items around with the mouse? a good example would be winamp's playlist. the code i came up with works fine...if you move your mouse slowly. if you go fast, it'll pretty much mess up the order because the cursor jumps around when you move your mouse too quickly.


    Dim HotItem1 As Integer

    Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    If HotItem1 <> List1.ListIndex Then
    If HotItem1 > -1 Then
    a = List1.List(HotItem1)
    b = List1
    List1.List(List1.ListIndex) = a
    List1.List(HotItem1) = b
    End If
    HotItem1 = List1.ListIndex
    List1_Click
    End If
    Else
    HotItem1 = -1
    End If

    End Sub

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Have u tried:
    VB Code:
    1. List1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    i think winamp made ther own listbox. this is a foolproof way but it flickers:

    VB Code:
    1. Dim lstIndex
    2. Private Type POINTAPI
    3.     X As Long
    4.     Y As Long
    5. End Type
    6.  
    7. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    8. Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
    9. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
    10. Private Const LB_ITEMFROMPOINT = &H1A9
    11.  
    12. Private Sub Form_Load()
    13.     Dim iIndex As Integer
    14.     For iIndex = 0 To 99
    15.         List1.AddItem "Item" & iIndex
    16.     Next
    17. End Sub
    18.  
    19.  
    20. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    21. lstIndex = List1.ListIndex
    22. Debug.Print lstIndex
    23. End Sub
    24.  
    25. Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    26.     Dim tPOINT As POINTAPI
    27.     Dim iIndex As Long
    28.  
    29. If Button = 1 Then
    30.         Call GetCursorPos(tPOINT)
    31.         Call ScreenToClient(List1.hWnd, tPOINT)
    32.         iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.X And &HFF) Or (&H10000 * (tPOINT.Y And &HFF))))
    33.         If iIndex > 65550 Then Exit Sub
    34.         Debug.Print iIndex
    35.         a = List1.List(lstIndex)
    36.         List1.RemoveItem lstIndex
    37.         List1.AddItem a, iIndex
    38.         lstIndex = iIndex
    39. End If
    40. End Sub

    you need a listbox called List1
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    i live where you don't
    Posts
    76
    it causes an overflow error when you drag it below the listbox. i tried slapping on an error trapper, but that didn't work too well. i tried something similar to your code, but couldn't get rid of the ugly flickering, so i didn't end up using it. anyone else? i know there are plenty of progammers out there who can help me out...

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