
Adding Sorting Arrows to a ListBox ??
Hi!
On a form, add two ListBoxes (List1 and List2), set the "Visible" property
of List2 to "False", and insert some items in List1; add two CommandButtons
(cmdUP and cmdDOWN); put this code in the declaration section of the form:
Private Sub cmdUP_Click()
Dim NewIndex As Integer
Dim X As Integer
If List1.ListIndex <= 0 Then Exit Sub
NewIndex = List1.ListIndex - 1
List2.Clear
For X = 0 To List1.ListCount - 1
If X = NewIndex Then
List2.AddItem List1.Text
List2.AddItem List1.List(X), NewIndex + 1
ElseIf X <> NewIndex + 1 Then
List2.AddItem List1.List(X)
End If
Next X
List1.Clear
For X = 0 To List2.ListCount - 1
List1.AddItem List2.List(X)
Next X
List1.ListIndex = NewIndex
End Sub
Private Sub cmdDOWN_Click()
Dim NewIndex As Integer
Dim X As Integer
If List1.ListIndex = List1.ListCount - 1 Or List1.ListIndex = -1 Then
Exit Sub
NewIndex = List1.ListIndex + 1
List2.Clear
For X = 0 To List1.ListCount - 1
If X = NewIndex Then
List2.AddItem List1.List(X), NewIndex - 1
List2.AddItem List1.Text
ElseIf X <> NewIndex - 1 Then
List2.AddItem List1.List(X)
End If
Next X
List1.Clear
For X = 0 To List2.ListCount - 1
List1.AddItem List2.List(X)
Next X
List1.ListIndex = NewIndex
End Sub
=====
Note that this code isn't optiomized, but it shows in a clear way how to
change the order of the items in the ListBox. If you have any kind of
problem, feel free to contact me again.
Bye
--
http://www2.armaditaggia.com/marco
http://www.geocities.com/SiliconValley/Foothills/7260/
Quote:
> Hi People,
> I have a list box that I would like the user to be able to change the
order
> of the names listed within by means of highlighting a name and then
clicking
> on an up or down arrow to move it up or down in the order.
> Any ideas???
> I have been searching for about 3 hours for a solution on the internet and
> my books.
> thanks,
> Kevin Rea