DOCERR: ListView/TreeView Sort Only on Text of ListItem/Node

Last reviewed: March 20, 1998
Article ID: Q153021
4.00    | 4.00
WINDOWS | WINDOWS NT kbprg kbdocerr

The information in this article applies to:

  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic for Windows, 32-bit only, version 4.0

SUMMARY

Although the documentation states that the ListView and TreeView controls can sort entries based on dates or numbers, in reality all sorting is done only on the textual representation of the items being sorted. This means, for example, that the number '11000' will be sorted before the number

'2000' if a sort is done in ascending order. This can also affect the
sorting of dates, depending on the format of the date in the text property of the ListItem or Node object.

STATUS

Microsoft has confirmed this to be a documentation error in the products mentioned at the beginning of this article.

MORE INFORMATION

This sorting functionality is provided by the COMCTL32.DLL file that ships with all 32-bit Windows operating systems. COMCTL32.OCX wraps this DLL to provide Windows 95-style common controls to Visual Basic programmers. If a series of documents are created and sorted in Explorer, they will show the same behavior noted in this article and demonstrated in the Step To Reproduce sample below. When in ascending order, numbers will be sorted before alphabetic characters, and A will be sorted before Z. Special characters such as accents, umlauts, tildes, and carets are sorted immediately after the character preceding them, without the corresponding special character. These rules are reversed when sorting is done in descending order.

Steps To Reproduce

  1. Start Visual Basic 4.0, 32-bit version. Form1 is created by default.

  2. Add a single ListView control to the form.

  3. Add this code to the form:

       Private Sub Form_Click()
           ListView1.SortOrder = 0
           ListView1.Sorted = True
           MsgBox "Sorted in ascending order"
       End Sub
    
       Private Sub Form_Load()
           Dim i As ListItem
    
           Set i = ListView1.ListItems.Add(, , "2000")
           Set i = ListView1.ListItems.Add(, , "11000")
       End Sub
    
    

  4. Press F5 or select Start from the Run menu to run the application. Click once on the form and dismiss the "Sorted in ascending order message box". Observe that the number "11000" has been sorted before the number "2000".


Additional reference words: 4.00 vb4win vb432
KBCategory: kbprg kbdocerr
KBSubcategory: PrgCtrlsCus
Keywords : PrgCtrlsCus kbdocerr kbprg
Version : 4.00 | 4.00
Platform : NT WINDOWS


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: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.