Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorting ListBox Index (Word XP)

    I'm using the lovely ListBox option and was wondering if there is a way of sorting a listbox. I have two listboxes, one with all the information and the other that picks up the items from the first list box via the user "moving" them over from box 1 to box 2 with a CommandButton (in no particular order).

    Example : List box 1 has 10 items, the user clicks on an item in List Box 1 (item 4), then moves it to List Box 2, goes back to List Box 1 and selects item 5, item 3 and item 7. List Box 2 has item 4, item 5, item 3 and item 7 (in that order). I would like to put the items in the correct order eg item 3, item 4, item 5 and item 7.

    Any help would be greatly appreciated.
    Many thanks
    Jackie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sorting ListBox Index (Word XP)

    You must either write your own sort routine, or use the old WordBasic.SortArray method - it still works in Word 2002. See the long thread starting at <post#=66671>post 66671</post#> for an extensive discussion of SortArray.

    The code using SortArray looks like this for a list box named ListBox1:

    Dim myArray()
    Dim i As Integer
    ' Define array size
    ReDim myArray(0 To ListBox1.ListCount - 1)
    ' Fill array from list box
    For i = 0 To ListBox1.ListCount - 1
    myArray(i) = ListBox1.List(i)
    Next i
    ' Sort array
    WordBasic.sortarray myArray
    ' Fill list box from array
    ListBox1.List = myArray

  3. #3
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting ListBox Index (Word XP)

    Many thanks Hans - It was starting to drive me a bit mad !! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •