Microsoft KB Archive/153021

= DOC: ListView Sort Only on Text of ListItem =

Article ID: 153021

Article Last Modified on 7/14/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q153021



SUMMARY
The documentation for the SortOrder Property of a ListView control states that you can "sort from the beginning of the alphabet (A-Z), the earliest date, or the lowest number." This is incorrect. 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 object.



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 file to provide Windows 95-style common controls to Visual Basic programmers. If a series of documents is created and sorted in Explorer, it 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 Behavior:
 Start Visual Basic 4.0, 32-bit version. Form1 is created by default. Add a single ListView control to the form.  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  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".

Microsoft has confirmed this to be a documentation error in the products mentioned at the beginning of this article. This error has been corrected in the documentation for Visual Basic 5.0 and 6.0

Keywords: kbinfo kbdocfix kbcontrol KB153021

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.