Noname > 27-08-10, 09:56 AM
Function SortListBox(objListBox As ListBox)
Dim intFirst As Integer
Dim intLast As Integer
Dim intNumItems As Integer
Dim i As Integer
Dim j As Integer
Dim strTemp As String
Dim MyArray() As Variant
'Re-Dim the array
ReDim MyArray(objListBox.ListCount - 1)
'Get upper and lower boundary
intFirst = LBound(MyArray)
intLast = UBound(MyArray)
'Set array values
For i = LBound(MyArray) To UBound(MyArray)
MyArray(i) = objListBox.ItemData(i)
Next i
'Loop through array values to determine sort
For i = intFirst To intLast - 1
For j = i + 1 To intLast
If MyArray(i) > MyArray(j) Then
strTemp = MyArray(j)
MyArray(j) = MyArray(i)
MyArray(i) = strTemp
End If
Next j
Next i
'Remove all items
For i = intLast - 1 To intFirst Step -1
objListBox.RemoveItem i
Next i
'Add all items in order
For i = intFirst To intLast - 1
objListBox.AddItem MyArray(i), i
Next
End Function
Private Sub Command1_Click()
Call SortListBox(List0)
End Sub
hoangthanhhai > 07-06-11, 03:03 PM
(27-08-10, 09:56 AM)Noname Đã viết: Mới lang thang tìm thấy 1 đoạn code cho phép Sort 1 Listbox theo Alphabe. Mời mọi người tham khảo, có gì thắc mắc cứ comment hỏi nhé!
Mời xem demo:
SortList
donxxiii > 21-10-11, 08:46 PM
kagetsu > 13-03-12, 12:53 PM