Here's how. Put these in the general declarations section of a module
Private m_iSortCol As Integer
Private m_iSortType As Integer
Private WithEvents msflexgrid2 As MSFlexGrid
Now onto the module itself
Private Sub msflexgrid2_dblclick()
On Error GoTo err_handler
'-------------------------------------------------------------------------------------------
' code in grid's DblClick event enables column sorting
'-------------------------------------------------------------------------------------------
Dim i As Integer
' sort only when a fixed row is clicked
If msflexgrid2.MouseRow >= msflexgrid2.FixedRows Then
Exit Sub
End If
i = m_iSortCol ' save old column
m_iSortCol = msflexgrid2.MouseCol ' set new column
' increment sort type
If i <> m_iSortCol Then
' if clicking on a new column, start with ascending sort
m_iSortType = 1
Else
' if clicking on the same column, toggle between ascending and descending sort
m_iSortType = m_iSortType + 1
If m_iSortType = 3 Then m_iSortType = 1
End If
With msflexgrid2
.Redraw = False
.Row = 1
.RowSel = .Rows - 1
.col = m_iSortCol
.Sort = m_iSortType
.Redraw = True
End With
endit:
Exit Sub
err_handler:
MsgBox _
"An unexpected error has been detected" & Chr(13) & _
"Description is: " & Err.Number & " , " & Err.Description & Chr(13) & _
"Module is: userform5.msflexgrid2_dblclick" & Chr(13) & _
"Please note the above details before contacting support", , " Unexpected Error"
Resume endit
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.