Object Reference > True DBGrid Events > BeforeUpdate Event |
BeforeUpdate Event
The BeforeUpdate event occurs before data is moved from the grid's internal copy buffer to the Data control's copy buffer and then written to the database.
TDBGrid_BeforeUpdate (Cancel As Integer)
Arguments
Cancel is an integer that may be set to True to prevent the update from occurring.
When the user moves to another row, or the Update method of the grid or Recordset object is executed, data is moved from the grid's copy buffer to the Data control's copy buffer and then written to the database.
Just before the data is moved from the grid's copy buffer back into the Data control's copy buffer, the BeforeUpdate event is triggered. Unless the copy operation is canceled, the AfterUpdate event is triggered after the data has been moved back into the Data control's copy buffer and written to the database.
The Bookmark property can be used to access the updated record.
If your event procedure sets the Cancel argument to True, focus remains on the control, the AfterUpdate event is not triggered, and the record is not saved to the database.
You can use this event to validate data in a record before permitting the user to commit the change to the Data control's copy buffer. Setting the Cancel argument to True prevents the user from moving focus to another control until the application determines whether the data can be safely moved back to the Data control's copy buffer.
Note
The event will not fire when the grid (OLE DB only) is bound to a Recordset or ADODC that has the .LockType property set to adLockBatchOptimistic.