FIX: ListBox Sorted Property Does Not SortID: Q180493
|
When a ListBox Sorted property is set to True, the items in the ListBox are not sorted.
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.
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
Microsoft has confirmed this to be a problem in the Microsoft products listed
at the beginning of this article.
This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.
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
Additional query words: vbce vbce5 vbce6 wince
Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: February 25, 1999