INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

VBA How To

Sorting a programmatically created MSFLEXGRID by double clicking on its header columns by taupirho
Posted: 29 Jun 04





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

End Sub


Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close