by Louis (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 3rd January 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
MSFlexGrid sorted by time column
'This article was contributed by
'Louis Orlando
'Houston Medical Records, Inc.
'[email protected]
'March 2002
'
'The MSFlexGrid will not properly sort a column containing
'time (ie: 8:30 AM). An easy solution is to create a
'hidden column containing the decimal equivalent of the
'time and to sort on that column. Note that to make a
'hidden column you must use the .ColWidth(colx) property
'of the MSFlexGrid and set it to zero because the .ColIsVisible(colx)
'property is Read-Only (the Microsoft documentation is incorrect).
' MSFlexGrid sort on time column
' Note: uses a hidded column with decimal time value to perform sort
' Requires: form with MSFlexGrid control & Command button
Private Sub Form_Load()
Call StuffGrid
End Sub
Private Sub StuffGrid()
Dim ogrid As MSFlexGrid
Set ogrid = MSFlexGrid1
Dim t(6) As String, lcol As Long
lcol = 2
t(1) = "10:00 AM"
t(2) = "11:30 AM"
t(3) = "9:00 AM"
t(4) = "11:00 AM"
t(5) = "3:00 PM"
t(6) = "2:00 PM"
ogrid.Cols = 3
ogrid.Rows = 7
ogrid.ColWidth(lcol) = 0 ' the .ColIsVisible(lcol) does not work
For r = 1 To 6
ogrid.TextMatrix(r, 1) = t(r)
x = TimeValue(t(r))
z = CSng(x)
ogrid.TextMatrix(r, 2) = z
Next r
End Sub
Private Sub GridSort()
MSFlexGrid1.Col = 2
MSFlexGrid1.Sort = 1
End Sub
Private Sub cmdSort_Click()
Call GridSort
End Sub