Unbound Mode > Unbound Mode Programming Considerations > Adding rows in modes 1 and 2 |
True DBGrid does not provide an AddNew method to complement Update and Delete since it cannot anticipate the requirements of the underlying data source. However, you can use the ApproxCount property and ReOpen method to resynchronize the grid after adding one or more rows in code.
The following example assumes that the data source is a two-dimensional array. It allocates storage space for a new row, informs the grid that the total number of rows has changed, then calls the grid's ReOpen method to force the grid to refetch data and position to the newly added row:
Example Title |
Copy Code
|
---|---|
' General declarations. Dim MaxRow As Long Dim MaxCol As Integer Dim MyArray() As String ' Assume that MyArray is one-based. MaxRow = MaxRow + 1 ReDim Preserve MyArray(1 To MaxRow, 1 To MaxCol) ' Update the number of rows. TDBGrid1.ApproxCount = MaxRow ' ReOpen the data source and make MaxRow the current row. TDBGrid1.ReOpen MaxRow |