Unicode Controls & Classes for VB6 - Version 4

ctlUniListView.SortCompareRows Event

Raised when the [SortWithCustomEvent] property is True and permits you to sort rows in a custom way

Syntax
Public Event SortCompareRows (ByRef vColKey As Variant,
ByVal iRow1 As Long,
ByVal iRow2 As Long,
ByRef bRetFirstIsGreater As Boolean)
Parameters
Parameter Description
ByRef vColKey As Variant The column identifier to test
ByVal iRow1 As Long The first comparison row
ByVal iRow2 As Long The second comparison row
ByRef bRetFirstIsGreater As Boolean Return True if the data on the first item is greater than the second
Remarks
In this sample a ListView control with SortWithCustomEvent property set to True uses the following code for sorting rows using the item tag
'Sorts rows using a custom event verifying item tags
Private Sub ctlUniListView1_SortCompareRows( _
vColKey As Variant, _
ByVal iRow1 As Long, _
ByVal iRow2 As Long, _
bRetFirstIsGreater As Boolean)

Dim Tag1 As Long 'Suppose the Tag contains numbers for comparison
Dim Tag2 As Long 'Suppose the Tag contains numbers for comparison
Dim oCol As clsUniLV_ColumnHeader
Set oCol = ctlUniListView1.ColumnHeaders.Item(vColKey)

Dim oItem1 As clsUniLV_ListItem
Dim oItem2 As clsUniLV_ListItem
Set oItem1 = ctlUniListView1.ListItems.Item(iRow1)
Set oItem2 = ctlUniListView1.ListItems.Item(iRow2)

If oCol.Index = 1 Then
Tag1 = oItem1.Tag
Tag2 = oItem2.Tag
ElseIf oCol.Index > 1 Then
If oItem1.ListSubItems.Count >= oCol.Index - 1 Then
Tag1 = oItem1.ListSubItems.Item(oCol.Index - 1).Tag
End If
If oItem2.ListSubItems.Count >= oCol.Index - 1 Then
Tag2 = oItem2.ListSubItems.Item(oCol.Index - 1).Tag
End If
End If

If ctlUniListView1.SortOrder = elvso_ascending Then
bRetFirstIsGreater = (Tag1 > Tag2)
Else
bRetFirstIsGreater = (Tag1 < Tag2)
End If
End Sub