Filling a Grid with Data from a DatabaseExample
The first example accepts a grid and clears the contents of all cells in the grid.
Sub ClearGrid (G As Grid)
Dim StartCol As Integer, EndCol As Integer
Dim StartRow As Integer, EndRow As Integer
StartCol = G.SelStartCol ' Save current location.
EndCol = G.SelEndCol
StartRow = G. Row
EndRow = G.SelEndRow
G.SelStartCol = 0 ' Select all cells.
G.SelEndCol = G.Cols - -1
G.SelStartRow = 0
G.SelEndRow = G.Rows - 1
G.Clip = "" ' Clear all cells.
G.SelStartCol = StartCol ' Return to starting location.
G.SelEndCol = EndCol
G.SelStartRow = StartRow
G.SelEndRow = EndRow
End Sub
This example (for the Professional Edition only) accepts a Snapshot and a grid, uses the first example to clear the grid, then fills the grid with the contents of the Snapshot.
Sub FillGrid (Sn As Snapshot, G As Grid)
Dim I As Integer
Sn.MoveLast ' Count the records.
G.Rows = Sn.RecordCount + 1 ' Set the rows.
G.Cols = Sn.Fields.Count + 1 ' Set the columns.
ClearGrid G
Sn.MoveFirst
Do Until Sn.EOF ' Loop through the Snapshot.
On Error Resume Next
For I = 0 to G.Cols - 1 ' Cycle through the columns.
G.Col = I ' Set the column number.
If I = 0 Then ' If first column...
G.Text = I ' Set the value.
Else
G.Text = Sn(I)
End If
Next I
On Error Goto 0
Sn.MoveNext ' Move to next record.
G.Row = G.Row + 1 ' Set the row number.
Loop
End Sub