The following example fills the grid with file names from the Windows directory and group them by year created. To try the example, place a SGGrid on a form. Paste the code into the Declarations section and press F5.
Private Sub Form_Load()
Dim sFile As String
Dim sgCol As SGColumn
Dim sWinDir As String
Dim dtFileDate As Date
Dim i As Integer
'remove all columns
SGGrid1.Columns.RemoveAll True
'misc stuff
SGGrid1.GroupByBoxVisible = False
SGGrid1.ColumnClickSort = True
'Column creations
Set sgCol = SGGrid1.Columns.Add("File")
sgCol.Caption = "File name"
sgCol.Width = 2200
Set sgCol = SGGrid1.Columns.Add("FileDate")
sgCol.Caption = "File date"
sgCol.Width = 2200
sgCol.DataType = sgtDateTime
sgCol.SortType = sgSortTypeDateTime
Set sgCol = SGGrid1.Columns.Add("Size")
sgCol.Caption = "Size"
sgCol.DataType = sgtLong
Set sgCol = SGGrid1.Columns.Add("FileYear")
sgCol.Hidden = True
sgCol.Caption = "File year"
sWinDir = Environ("WINDIR") & "\"
sFile = Dir(sWinDir & "*.*", vbNormal)
Do Until Len(sFile) = 0
i = i + 1
SGGrid1.DataRowCount = i
SGGrid1.Rows.At(i).Cells(0).Value = sFile
dtFileDate = FileDateTime(sWinDir & sFile)
SGGrid1.Rows.At(i).Cells(1).Value = dtFileDate
SGGrid1.Rows.At(i).Cells(2).Value = FileLen(sWinDir & sFile)
SGGrid1.Rows.At(i).Cells(3).Value = Year(dtFileDate)
sFile = Dir
Loop
SGGrid1.Groups.Add "FileYear", sgSortAscending, sgSortTypeNumber, , True
SGGrid1.CollapseAll
End Sub
Back to topic