Application Mode > Application Mode Events > Handling the ClassicAdd event in mode 3 |
If the AllowAddNew and AllowUpdate properties of the grid are True, then users can add new records to the grid, and you must implement the ClassicAdd event. The syntax of this event is as follows:
Example Title |
Copy Code
|
---|---|
Private Sub TDBGrid1_ClassicAdd(NewRowBookmark As Variant, _ ByVal Col As Integer, Value As Variant) |
NewRowBookmark is a variable which receives the bookmark for the newly added row. Initially, the NewRowBookmark argument is Null. However, before returning from this event, you must set it to a bookmark that uniquely identifies the newly added row. If you do not set the value of NewRowBookmark, the add operation will fail and the grid will not allow its current row to change.
Col is a value which specifies the column index of data that has been added.
Value is the data that corresponds to the newly added cell.
Before returning from this event, you must update the underlying data source with Value and set the NewRowBookmark argument to the bookmark of the newly added row. If, for some reason, the add cannot be completed, you can set NewRowBookmark to Null in order to force the grid to cancel the AddNew operation initiated by the user.
Note that the ClassicAdd event will fire once for each modified cell in the new row. This does not pose a problem if the underlying data source permits you to add blank records. However, if this is not the case, and you are using unique key field values as bookmarks, you cannot assume that the event will fire for the key field column first. Since you must still supply a valid bookmark (even if you don't know what it is yet), you can set NewRowBookmark to a special key that will never refer to a real record. Then, when the ClassicAdd event fires for the key field column (and subsequent columns), you can return the actual bookmark. The grid will use the last bookmark it receives and discard the special key that you supplied earlier.