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
Printable View
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
May be this helps....
VB Code:
'Declaration Private m_SortColumn As Integer Private m_SortAscending As Integer ------------------------------------- Private Sub MSFlexGrid1_Click() ' See if the user clicked row 0. If MSFlexGrid1.MouseRow > 0 Then Exit Sub ' See if this is the same column. If MSFlexGrid1.MouseCol = m_SortColumn Then ' This is the current sort column. ' Change the sort order and the column title. m_SortAscending = Not m_SortAscending If m_SortAscending Then MSFlexGrid1.TextMatrix(0, m_SortColumn) = _ "> " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3) Else MSFlexGrid1.TextMatrix(0, m_SortColumn) = _ "< " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3) End If Else ' This is a new sort column. ' Restore the previous sorting column's name. If m_SortColumn >= 0 Then MSFlexGrid1.TextMatrix(0, m_SortColumn) = _ Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3) End If ' Save the new sort column. m_SortColumn = MSFlexGrid1.MouseCol ' Sort using the new column. m_SortAscending = True MSFlexGrid1.TextMatrix(0, m_SortColumn) = _ "> " & MSFlexGrid1.TextMatrix(0, m_SortColumn) End If MSFlexGrid1.Row = 1 MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1 MSFlexGrid1.Col = m_SortColumn If m_SortAscending Then Select Case m_SortColumn Case 2, 5, 6 MSFlexGrid1.Sort = flexSortNumericAscending Case Else MSFlexGrid1.Sort = flexSortStringAscending End Select Else Select Case m_SortColumn Case 2, 5, 6 MSFlexGrid1.Sort = flexSortNumericDescending Case Else MSFlexGrid1.Sort = flexSortStringDescending End Select End If End Sub
Cheers mate, worked a treat, except that i changed the first line to look at the row rather than the mouserow
Dan:)
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
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) :(