Click to See Complete Forum and Search --> : Moving items in a listbox
heavenhell
Mar 2nd, 2001, 10:44 AM
Is there any way i can reposition items in a listbox by dragging??
Try this:
Private Sub Form_Load()
List1.Clear
For I = 0 To 10
List1.AddItem "Item" & I
Next I
End Sub
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
With List1
If .ListCount = -1 Then Exit Sub
If KeyCode = vbKeyDown Then
If .ListIndex + 1 = .ListCount Then Exit Sub
Tmp = .ListIndex
.AddItem .List(.ListIndex), .ListIndex + 2
.RemoveItem .ListIndex
.Refresh
.ListIndex = Tmp
End If
If KeyCode = vbKeyUp Then
If .ListIndex = 0 Then Exit Sub
Tmp = .ListIndex
.AddItem .List(.ListIndex), Tmp - 1
.RemoveItem Tmp + 1
.Refresh
.ListIndex = Tmp
End If
End With
End Sub
See this thread (http://forums.vb-world.net/showthread.php?s=&threadid=27198)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.