The following example uses the Sort and TextMatrix properties. It performs an MSHFlexGrid sort according to the value of a ComboBox control. To use the example, place an MSHFlexGrid control and a ComboBox control on a form. Paste the following code into the Declarations section, and then press f5.
Note If you are using the MSFlexGrid, substitute "MSHFlexGrid1" with "MSFlexGrid1."
Private Sub Combo1_Click()
' Select Column according to Sort method.
Select Case Combo1.ListIndex
Case 0 To 2
MSHFlexGrid1.Col =1
Case 3 To 4
MSHFlexGrid1.Col =2
Case 4 To 8
MSHFlexGrid1.Col =1
End Select
' Sort according to Combo1.ListIndex.
MSHFlexGrid1.Sort =Combo1.ListIndex
End Sub
Private Sub Form_Load()
Dim i As Integer
' Fill MSHFlexGrid with random data.
MSHFlexGrid1.Cols =3 ' Create three columns.
For i =1 To 11 ' Add ten items.
MSHFlexGrid1.AddItem ""
MSHFlexGrid1.Col =2
MSHFlexGrid1.TextMatrix(i, 1) =SomeName(i)
MSHFlexGrid1.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 "flexSortStringNoCaseAsending" '5
.AddItem "flexSortNoCaseDescending" '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