Results 1 to 5 of 5

Thread: sort a listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4

    Post

    Hi,
    How to sort a listbox witout code?
    Is exists a method for that?
    Thanks

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can change the Sorted property to True in design time.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'unfortunately it won't sort numerics properly
    '
    'example being.
    
    Private Sub Form_Load()
        List1.AddItem 5
        List1.AddItem 5001
        List1.AddItem 50
        List1.AddItem 111
        List1.AddItem 11
        List1.AddItem 10001
        List1.AddItem 333
        List1.AddItem 11101
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Not a problem:
    Code:
    Public Sub SortListNumberic(p_List As ListBox)
        Dim i
        Dim j
        Dim lngTemp As Long
         
        For i = p_List.ListCount - 1 To 0 Step -1
            For j = 1 To i
                If Val(p_List.List(j - 1)) > Val(p_List.List(j)) Then
                    lngTemp = p_List.List(j - 1)
                    p_List.List(j - 1) = p_List.List(j)
                    p_List.List(j) = lngTemp
                End If
            Next
        Next
    End Sub
    
    
    Private Sub Command2_Click()
        Call SortListNumberic(List1)
    End Sub
    
    
    Private Sub Form_Load()
        List1.AddItem 5
        List1.AddItem 5001
        List1.AddItem 50
        List1.AddItem 111
        List1.AddItem 11
        List1.AddItem 10001
        List1.AddItem 333
        List1.AddItem 11101
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    4
    THANKS FOR YOUR HELP!!!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width