devxlogo

Sorting MSFlexGrid

Sorting MSFlexGrid

Ever wonder how to get the MSFlexGrid to have sorting behavior common inmany Windows applications? That is to say when you double-click on acolumns header it sorts ascending. Double-click again and it sortsdescending. The following code demonstrates the basic modificationsnecessary to make this work. Note: In this sample flexSortGenericAscendingand flexSortGenericDescending are used. Of course you can modify this tosort more specifically based on the column.

 =====================================================================Prerequisites:  Add a grdInformation to your form and populate it.=====================================================================Private mintMyRow As Integer            'Holds Last RowPrivate mintMyCol As Integer            'Holds Last ColPrivate mintLastSort(8) As Integer      'Array with column's lastsort 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    Else      grdInformation.Sort = 1      mintLastSort(mintMyCol) = 1       'Generic Ascending    End If  End If    End Sub----------------------------------------------------------------------------Private Sub grdInformation_MouseDown(Button As Integer, Shift As Integer, xAs Single, y As Single)    mintMyRow = grdInformation.MouseRow    mintMyCol = grdInformation.MouseCol  End Sub
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist