Compare Event

Fired when the Sort property is set to flexSortCustom, to allow custom comparison of rows.

Syntax

Private Sub VSFlexGrid_Compare( ByVal Row1 As Long,  ByVal Row2 As Long, Cmp As Integer)

Remarks

When the Sort property is set to flexSortCustom, this event is fired several times, to compare pairs of rows.

The event handler should compare rows Row1 and Row2 and return the result in the Cmp parameter. The result should be:

 

Value

Description

-1

If Row1 should appear before Row2.

0

If the rows are equal (as far as sorting goes).

+1

If Row1 should appear after Row2.

 

Note that custom sorts are orders of magnitude slower than the built-in sorts, so you should avoid using them unless your data sets are small. Usually, there are good alternatives to a custom sort:

If you are sorting dates, set the ColDataType property to flexDTDate and the generic sorting settings will sort the dates correctly.

If you are sorting international strings, the generic and string settings will sort the value correctly.

If you want to sort based on arbitrary criteria (for example, "Urgent", "High", "Medium", "Low"), use a hidden column with numerical values that correspond to the criteria you are using.

See Also

VSFlexGrid Control