If you're using VB6 then see if this sample works for you:
Code:
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
With MSFlexGrid1
.Rows = 10
.Cols = 5
For j = 0 To .Rows - 1
For i = 0 To .Cols - 1
.TextMatrix(j, i) = j + 1 * (i + 1)
Next i
Next j
End With
MSFlexGrid1_Click 'force sort asc
End Sub
Private Sub MSFlexGrid1_Click()
Static sortA As Boolean
With MSFlexGrid1
.RowSel = .Row
.Col = .Col
.ColSel = .Col
If Not sortA Then
.Sort = flexSortGenericAscending
sortA = True
Else
.Sort = flexSortGenericDescending
sortA = False
End If
End With
End Sub
Also, original idea was posted here. Read all the comments.