Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Sep 13, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Sorting MSFlexGrid

Ever wonder how to get the MSFlexGrid to have sorting behavior common in many Windows applications? That is to say when you double-click on a columns header it sorts ascending. Double-click again and it sorts descending. The following code demonstrates the basic modifications necessary to make this work. Note: In this sample flexSortGenericAscending and flexSortGenericDescending are used. Of course you can modify this to sort more specifically based on the column.

Prerequisites:  Add a grdInformation to your form and populate it.
Private mintMyRow As Integer            'Holds Last Row
Private mintMyCol As Integer            'Holds Last Col
Private mintLastSort(8) As Integer      'Array with column's last
sort value
Private Sub grdInformation_DblClick()
  If mintMyRow = 0 Then             'On header row?
    If mintLastSort(mintMyCol) = 1 Then 'Already sorted ascending?
      grdInformation.Sort = 2
      mintLastSort(mintMyCol) = 2       'Generic Descending
      grdInformation.Sort = 1
      mintLastSort(mintMyCol) = 1       'Generic Ascending
    End If
  End If
End Sub

Private Sub grdInformation_MouseDown(Button As Integer, Shift As Integer, x
As Single, y As Single)
  mintMyRow = grdInformation.MouseRow  
  mintMyCol = grdInformation.MouseCol  
End Sub
Steve Guthrie
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date