TcxCustomDataController.BeginUpdate Method
Postpones sending update notifications by the data controller.
Declaration
procedure BeginUpdate;
Remarks
When you need to perform a series of operations, each of which leads to updating data and a resulting update notification by the data controller, consider using the BeginUpdate and EndUpdate methods.
For instance, each time you change the number of records in your data controller or modify a record’s value, the data controller automatically sends an update notification to the control (ExpressQuantumGrid, for instance) displaying its data. In this case, you can enclose the code performing these operations within the BeginUpdate and EndUpdate method calls. This ensures that the control is only updated once.
Each call to BeginUpdate must correspond to a call to the EndUpdate method. To ensure that EndUpdate is called even if an exception occurs, you should use a try…finally block.
Note
Do not call the Append, Insert, Post, SetEditValue, and FindRecordIndexByText methods within the BeginUpdate/EndUpdate and BeginFullUpdate/EndFullUpdate blocks.
The following code shows how to add and fill a new record in unbound mode in a tvPlanets View of the ExpressQuantumGrid control. The APeriodIndex, ADistanceIndex, ANameIndex and AOrbitsIndex variables specify the indexes of the columns to fill.
var
ARecordIndex: Integer;
//...
with tvPlanets.DataController do
begin
BeginUpdate;
ARecordIndex := InsertRecord(FocusedRecordIndex);
try
Values[ARecordIndex, APeriodIndex] := 87.97;
Values[ARecordIndex, ADistanceIndex] := 57910;
Values[ARecordIndex, ANameIndex] := 'Mercury';
Values[ARecordIndex, AOrbitsIndex] := 'Sun';
finally
EndUpdate;
end;
end;