This is a bit foolish question bu I forgot how to do it.
I want to move items listed in the list box up or down. How do I do it?
Kinjal
Printable View
This is a bit foolish question bu I forgot how to do it.
I want to move items listed in the list box up or down. How do I do it?
Kinjal
Havent tested it yet but see if it worksCode:Private Sub Form_Load()
For n = 0 To 10
List1.AddItem n
Next n
End Sub
Private Sub List1_Click()
List1.AddItem List1.List(List1.ListIndex), 1
List1.RemoveItem List1.List(List1.ListIndex + 1)
End Sub
The items are already added to the list box and I wan to change their position i.e move the entries up or down using command buttons.
No Kedaman it's not working. The program shows error whenever I click the list box.
what error? where?
This seems to work. Create a new form with a listbox, and two command buttons. cmdUp and cmdDown. When the user highlights an item in the list, then clicks the up or down button, the highlighted item will move up or down...
Private Sub cmddown_Click()
Dim ts As String
Dim tindex As Integer
tindex = List1.ListIndex
If tindex < List1.ListCount - 1 Then
ts = List1.List(tindex + 1)
List1.List(tindex + 1) = List1.List(tindex)
List1.List(tindex) = ts
List1.ListIndex = tindex + 1
End If
End Sub
Private Sub cmdup_Click()
Dim ts As String
Dim tindex As Integer
tindex = List1.ListIndex
If tindex > 0 Then
ts = List1.List(tindex - 1)
List1.List(tindex - 1) = List1.List(tindex)
List1.List(tindex) = ts
List1.ListIndex = tindex - 1
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 10
Me.List1.AddItem Str(i)
Next
End Sub
perfect.... thank you,
I needed this code too :D
Thanks a lot jmatello. :D
Kinjal
yeas, thank you, i was after this too :)