Results 1 to 2 of 2

Thread: Combobox Sort question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    BC, Canada
    Posts
    142
    As you know, sort property for Combobox is ready only and sorted in Ascending order. For my dynamically filled combobox(not sorted), if I want a descending order list, what Can I do?
    May I use API sendmessage call? I just visited web site "VB API" listed on your left screen but found nothing specially helpful. Any suggestion? In a situation like this, any internet resource I can use to find the answer by myself? You see, I am asking more than just answer here. Thanks

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    I don't think there's an API call that deals specifically with sorting a combo or listbox in descending order. However, you can develope a code yourself. Note: If you want to add a large amount of items and sort them, it make take some time to sort out, but if you want to have a combo/listbox that is never changed to be sorted, then sort it by hand. If you want to be able to add items one at a time, a code to place this item in the right place shouldn't take to long.

    Your code could be something like this for adding one item to the correct ascending order at a time (I think):
    Code:
    Dim i as Single, j as Single
    
    For i = 0 to List1.Listcount - 1
      For j = 1 to Len(Text1)
        If Left(Text1, j) = Left(List1.List(i), j) Then
          If Left(Text1, j + 1) <> Left(List1.List(i), j + 1) Then 
            List1.AddItem Text1, i + 1
            Exit Sub
          End If
        Else
          Exit For
        End If
      Next
    Next

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