Share via


Sort Property (ModHFGrid)

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Sets a value that sorts selected rows according to selected criteria. This property is 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 the ModHFGrid Control object.
value An integer or constant that specifies the type of sorting, as described in Settings.

Settings

The settings for value are:

Constant Value Description
flexSortNone 0 None. No sorting is performed.
flexSortGenericAscending 1 Generic Ascending. An ascending sort, which estimates whether text is string or number, is performed.
flexSortGenericDescending 2 Generic Descending. A descending sort, which estimates whether text is string or number, is performed.
flexSortNumericAscending 3 Numeric Ascending. An ascending sort, which converts strings to numbers, is performed.
flexSortNumericDescending 4 Numeric Descending. A descending sort, which converts strings to numbers, is performed.
flexSortStringNoCaseAscending 5 String Ascending. An ascending sort using case-insensitive string comparison is performed.
flexSortStringNoCaseDescending 6 String Descending. A descending sort using case-insensitive string comparison is performed.
flexSortStringAscending 7 String Ascending. An ascending sort using case-sensitive string comparison is performed.
flexSortStringDescending 8 String Descending. A descending sort using case-sensitive string comparison is performed.
flexSortCustom 9 Custom. This uses the Compare event to compare rows.

Remarks

The Sort property always sorts entire rows. To specify the range to be sorted, set the Row and RowSel properties. If Row and RowSel are the same, the ModHFGrid will sort all non-fixed rows.

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

The method used to compare the rows is determined by the value, as explained in Settings. The 9 (Custom) setting is the most flexible but is slower than the other settings, typically by a factor of 10. An alternative to using this setting is to create an invisible column, fill it with the keys, and then perform a sort based on Custom using another setting. This is a good approach for sorts that are based on dates.

Example

The following example uses the Sort and TextMatrix properties. It performs a ModHFGrid sort according to the value of a ComboBox control. To use the example, place a ModHFGrid control and a ComboBox control on a form. Paste the following code into the Declarations section, and then press F5.

Private Sub Combo1_Click()
' Select Column according to Sort method.
Select Case Combo1.ListIndex 
   Case 0 To 2
      ModHFGrid1.Col =1
   Case 3 To 4
      ModHFGrid1.Col =2
   Case 4 To 8
      ModHFGrid1.Col =1   
End Select

' Sort according to Combo1.ListIndex.
ModHFGrid1.Sort =Combo1.ListIndex 
End Sub

Private Sub Form_Load()
Dim i As Integer
' Fill ModHFGrid with random data.
ModHFGrid1.Cols =3 ' Create three columns.
For i =1 To 11 ' Add ten items.
   ModHFGrid1.AddItem ""
   ModHFGrid1.Col =2
   ModHFGrid1.TextMatrix(i, 1) =SomeName(i)
   ModHFGrid1.TextMatrix(i, 2) =Rnd()
Next i

' Fill combo box with Sort choices
With Combo1
   .AddItem "flexSortNone" ' 0
   .AddItem "flexSortGenericAscending" '1
   .AddItem "flexSortGenericDescending" '2
   .AddItem "flexSortNumericAscending" '3
   .AddItem "flexSortNumericDescending" '4
   .AddItem "flexSortStringNoCaseAscending" '5
   .AddItem "flexSortStringNoCaseDescending" '6
   .AddItem "flexSortStringAscending" '7
   .AddItem "flexSortStringDescending" '8
   .ListIndex =0
End With
End Sub

Private Function SomeName(i As Integer) As String
Select Case i
   Case 1
      SomeName ="Ann"
   Case 2
      SomeName ="Glenn"
   Case 3
      SomeName ="Sid"
   Case 4
      SomeName ="Anton"
   Case 5
      SomeName ="Hoagie"
   Case 6
      SomeName ="Traut 'Trane"
   Case 7
      SomeName ="MereD Wah"
   Case 8
      SomeName ="Kemp"
   Case 9
      SomeName ="Sandy"
   Case 10
      SomeName ="Lien"
   Case 11
      SomeName ="Randy"
End Select
End Function

See Also

Col, Row Properties (ModHFGrid) | ColSel, RowSel Properties (ModHFGrid) | Compare Event (ModHFGrid) | ModHFGrid Control