|
-
May 28th, 2002, 08:14 PM
#1
Thread Starter
Lively Member
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
-
May 28th, 2002, 08:25 PM
#2
Have u tried:
VB Code:
List1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
-
May 28th, 2002, 10:44 PM
#3
The picture isn't missing
i think winamp made ther own listbox. this is a foolproof way but it flickers:
VB Code:
Dim lstIndex
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
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
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
Dim iIndex As Integer
For iIndex = 0 To 99
List1.AddItem "Item" & iIndex
Next
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lstIndex = List1.ListIndex
Debug.Print lstIndex
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim tPOINT As POINTAPI
Dim iIndex As Long
If Button = 1 Then
Call GetCursorPos(tPOINT)
Call ScreenToClient(List1.hWnd, tPOINT)
iIndex = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0&, ByVal ((tPOINT.X And &HFF) Or (&H10000 * (tPOINT.Y And &HFF))))
If iIndex > 65550 Then Exit Sub
Debug.Print iIndex
a = List1.List(lstIndex)
List1.RemoveItem lstIndex
List1.AddItem a, iIndex
lstIndex = iIndex
End If
End Sub
you need a listbox called List1
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
May 29th, 2002, 12:08 AM
#4
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|