Results 1 to 5 of 5

Thread: Sorting Flexgrids

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    London
    Posts
    15

    Question Sorting Flexgrids

    Hi there,

    Does anyone know of a quick n' easy wasy to sort data in a flexgrid, for example by clicking on the column headers?

    Cheers

    Dan

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    245

    Lightbulb MSFlexGrid Sorting?

    May be this helps....
    VB Code:
    1. 'Declaration
    2. Private m_SortColumn As Integer
    3. Private m_SortAscending As Integer
    4.  
    5. -------------------------------------
    6.  
    7. Private Sub MSFlexGrid1_Click()
    8.  
    9.     ' See if the user clicked row 0.
    10.     If MSFlexGrid1.MouseRow > 0 Then Exit Sub
    11.  
    12.     ' See if this is the same column.
    13.     If MSFlexGrid1.MouseCol = m_SortColumn Then
    14.         ' This is the current sort column.
    15.         ' Change the sort order and the column title.
    16.         m_SortAscending = Not m_SortAscending
    17.         If m_SortAscending Then
    18.             MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
    19.                 "> " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
    20.         Else
    21.             MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
    22.                 "< " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
    23.         End If
    24.     Else
    25.         ' This is a new sort column.
    26.         ' Restore the previous sorting column's name.
    27.         If m_SortColumn >= 0 Then
    28.             MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
    29.                 Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
    30.         End If
    31.  
    32.         ' Save the new sort column.
    33.         m_SortColumn = MSFlexGrid1.MouseCol
    34.  
    35.         ' Sort using the new column.
    36.         m_SortAscending = True
    37.         MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
    38.             "> " & MSFlexGrid1.TextMatrix(0, m_SortColumn)
    39.     End If
    40.  
    41.     MSFlexGrid1.Row = 1
    42.     MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1
    43.     MSFlexGrid1.Col = m_SortColumn
    44.  
    45.     If m_SortAscending Then
    46.         Select Case m_SortColumn
    47.             Case 2, 5, 6
    48.                 MSFlexGrid1.Sort = flexSortNumericAscending
    49.             Case Else
    50.                 MSFlexGrid1.Sort = flexSortStringAscending
    51.         End Select
    52.     Else
    53.         Select Case m_SortColumn
    54.             Case 2, 5, 6
    55.                 MSFlexGrid1.Sort = flexSortNumericDescending
    56.             Case Else
    57.                 MSFlexGrid1.Sort = flexSortStringDescending
    58.         End Select
    59.     End If
    60. End Sub
    I may have interpret your post wrongly
    Correct me if I made a mistake...
    Hope This Helps.. .....Enjoy Coding.....//


    zak2zak

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    London
    Posts
    15

    Wink

    Cheers mate, worked a treat, except that i changed the first line to look at the row rather than the mouserow

    Dan

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    London
    Posts
    15
    Hi there again,

    Sorry to bother people, but my plan didn't work!!

    Using the row instead of mouserow keeps returning a value of 1 for both the fixedrow (column headers) and the first row of data in the table - this means that the user sorts when clicking on the first row of data as well as the fixedrow.

    Using mouserow to determine the position (as initially suggested) returns a value of 33 (the last row in the table) - how is this possible?

    Regards

    Dan

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Row cannot select a fixed row, so that is not a valid check.

    MouseRow only works while the form is visible, I presume you got the 33 by looking at the value in the IDE - try displaying it on the form somewhere instead (I use the form caption).

    If the form isn't visible when you check the MouseRow value, it simply returns the number of rows (because the form is hidden, the mouse is no longer on a row)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width