# Re: 如何使用DBGrid 在非连接摸式(unband) 下写入资料

Posted by tt on January 11, 1999 at 12:03:05:

In Reply to: 如何使用DBGrid 在非连接摸式(unband) 下写入资料 posted by TimLiu on January 09, 1999 at 18:13:10:

This example illustrates the use of the UnboundAddData event to add a row of data to a database, in this case, a simple array.

Private Sub DBGrid1_UnboundAddData(ByVal RowBuf As RowBuffer, NewRowBookmark As Variant)
Dim Col%

mTotalRows = mTotalRows + 1
ReDim Preserve UserData(MAXCOLS - 1, mTotalRows - 1)
'Sets the bookmark to the last row.
NewRowBookmark = mTotalRows - 1

' The following loop adds a new record to the database.
For Col% = 0 To UBound(UserData, 1)
If Not IsNull(RowBuf.Value(0, Col%)) Then
UserData(Col%, mTotalRows - 1) = RowBuf.Value(0, Col%)

Else
' If no value set for column, then use the
' DefaultValue
UserData(Col%, mTotalRows - 1) = DBGrid1.Columns(Col%).DefaultValue
End If
Next Col%
End Sub

Follow Ups: