Sort

Sets a value that sorts selected rows according to selected criteria. Not available at design time.

Syntax

object.Sort [=value]

The Sort property syntax has these parts:

Part Description
object An object expression that evaluates to an object.
value Integer or constant specifying the type of sorting, as described in Settings.

Settings

The settings for value are:

Value Description
0 None
1 Generic Ascending. Guesses whether text is string or number
2 Generic Descending
3 Numeric Ascending. Converts strings to numbers
4 Numeric Descending
5 String Ascending. Case-insensitive
6 String Descending. Case-insensitive
7 String Ascending. Case-sensitive
8 String Descending. Case-sensitive
9 Custom. Uses Compare event to compare rows

Remarks

The Sort property always sorts entire rows. The range to be sorted is specified by setting the Row and RowSel properties. If Row and RowSel are the same, Grid assumes that you want to sort all nonfixed rows.

The keys used for sorting are determined by the Col and ColSel properties, always from the left to the right. For example, if Col = 3 and ColSel = 1, the sort would be done according to the contents of columns 1, then 2, then 3.

The method used to compare the rows is determined by the setting, as explained above. The 9 (Custom) setting is the most flexible, since it fires the Compare event that allows you to compare rows in any way you want, using any columns in any order (see the Compare event for details). However, this method is also much slower that the others, typically by a factor of ten, so it should be used only when really necessary.

An alternative to using the 9 (Custom) setting is to create an invisible column, fill it with the keys, then sort based on it with one of the other settings. This is a very good approach for sorting based on dates, for example.