BUG: ListBox Sorted Property Does Not Sort

Last reviewed: February 5, 1998
Article ID: Q180493
The information in this article applies to:
  • Windows CE Toolkit for Visual Basic 5.0, version 1.0

SYMPTOMS

When a ListBox Sorted property is set to True, the items in the ListBox are not sorted.

RESOLUTION

This bug requires a sort routine to be implemented manually if the ListBox items need to be sorted. The following is a sample of how this might be accomplished.

  1. Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default.

  2. Place a ListBox (List1), a TextBox (Text1) and a CommandButton (Command1) on Form1.

  3. Paste the following code into the General Declarations section of Form1:

          Dim strArray()
          Private Sub Form_Load()
    
              'initialize the array
              ReDim strArray(0)
       
              AddItem strArray, "Utah"
              AddItem strArray, "Washington"
              AddItem strArray, "Virginia"
              AddItem strArray, "Iowa"
              AddItem strArray, "Oregon"
              AddItem strArray, "Alabama"
              AddItem strArray, "Mississippi"
              AddItem strArray, "Ohio"
       
              Sort strArray, List1
          End Sub
       
          Private Sub Command1_Click()
              If Text1.Text <> "" Then
                  AddItem strArray, Text1.Text
                  Sort strArray, List1
              End If
          End Sub
       
          Sub AddItem(inpArray(), inpItem)
              ReDim Preserve inpArray(UBound(inpArray) + 1)
              inpArray(UBound(inpArray)) = inpItem
          End Sub
       
          Sub Sort(inpArray(), inpList)
              Dim intRet
              Dim intCompare
              Dim intLoopTimes
              Dim strTemp
       
              For intLoopTimes = 1 To UBound(inpArray)
                  For intCompare = LBound(inpArray) To UBound(inpArray) - 1
                      intRet = StrComp(inpArray(intCompare), _
                               inpArray(intCompare + 1), vbTextCompare)
       
                      If intRet = 1 Then 'String1 is greater than String2
                          strTemp = inpArray(intCompare)
                          inpArray(intCompare) = inpArray(intCompare + 1)
                          inpArray(intCompare + 1) = strTemp
                      End If
                  Next
              Next
       
              'clear the list and repopulate.
              inpList.Clear
              For intCompare = 1 To UBound(inpArray)
                  inpList.AddItem inpArray(intCompare)
              Next
          End Sub
    
    

  4. Press the F5 key to run the Project.

  5. Type some text into Text1.

  6. Click Command1 to add the item into the ListBox, and note that the new item is in the proper sort order.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Windows CE Project in Visual Basic 5.0. Form1 is created by default.

  2. Place a ListBox (List1), a TextBox (Text1) and a CommandButton (Command1) on Form1.

  3. Set the Sorted property of List1 to True.

  4. Paste the following code into the General Declarations section of Form1:

          Option Explicit
    

          Private Sub Command1_Click()
    
               List1.AddItem Text1.Text
          End Sub
    
          Private Sub Form_Load()
               Command1.Caption = "Add Text To List Box"
               Text1.Text = ""
               List1.Clear
          End Sub
    
    

  5. Press the F5 key to run the project.

  6. Type "Washington" in Text1 and click Command1.

  7. Type "Alaska" in Text1 and click Command1.

  8. Type "Utah" in Text1 and click Command1.

  9. Note that they are not sorted.
Keywords          : vb5all vbce
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbbug
Solution Type     : kbpending


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.