by Agustin Caballero (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 12th January 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A function to sort a listview by a column of any type (date, time, number, text); it alternates sort order like the windows explorer
API Declarations
gcnNumber = 0
gcnText = 1
gcnDateTime = 2
End Enum
' Receives the listview, the column on which the click
' is made and type of data contained in the column
Dim li As ListItem
If lnType <> gcnText Then
For Each li In lsv.ListItems
If lncol > 1 Then
li.Tag = li.SubItems(lncol - 1)
Else
li.Tag = li.Text
End If
Next
For Each li In lsv.ListItems
Select Case lnType
Case gcnNumber
If lncol > 1 Then
li.SubItems(lncol - 1) = Format(mfnValorNumerico(li.SubItems(lncol - 1)), "0000000000.00000")
Else
li.Text = Format(mfnValorNumerico(li.Text), "0000000000.00000")
End If
Case gcnDateTime
If lncol > 1 Then
li.SubItems(lncol - 1) = Format(CVDate(li.SubItems(lncol - 1)), "yyyy/mm/dd hh:mm:ss")
Else
li.Text = Format(CVDate(li.Text), "yyyy/mm/dd hh:mm:ss")
End If
Case gcnText
End Select
Next
End If
If lsv.SortKey = lncol - 1 Then
lsv.SortOrder = IIf(lsv.SortOrder = lvwAscending, lvwDescending, lvwAscending)
Else
lsv.SortOrder = lvwAscending
lsv.SortKey = lncol - 1
End If
lsv.Sorted = True
If lnType <> gcnText Then
For Each li In lsv.ListItems ' Restauramos los valores
If lncol > 1 Then
li.SubItems(lncol - 1) = li.Tag
Else
li.Text = li.Tag
End If
li.Tag = ""
Next
End If
End Sub
No comments have been posted about A function to sort a listview by a column of any type (date, time, number, text); it alternates sor. Why not be the first to post a comment about A function to sort a listview by a column of any type (date, time, number, text); it alternates sor.