The rule is that everything in the grid can be done without beginupdate/endupdate, but if you need to load lots of data and this takes time use beginupdate/endupdate to speed up the process. Always use them outside of any grid event that manipulates cells such as OnGetCellLayout. Click events should be safe
procedure TBOMForm.MOBOMDATAGridAfterCloseInplaceEditor(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord; ACancel: Boolean;
AValue: TTMSFNCDataGridCellValue);
VAR
TCOST : DOUBLE;
LG : INTEGER;
begin
TCOST := 0;
if not ACancel then
begin
if MOBOMDATAGridDatabaseAdapter.DataLink.DataSet.State in [dsEdit] then
begin
MOBOMDATAGridDatabaseAdapter.DataLink.DataSet.Post;
LABEL9.Text := 'Status: Updated : '+AVALUE.ToString;
end;
if (acELL.Column = 7) and (aCELL.row = MOBOMDATAGrid.FocusedCell.Row) then
BEGIN
if (FDTbl9BA.FieldByName('STATUS').AsString = 'Entered') then
BEGIN
FDTBL9D.First;
while NOT FDTBL9D.EOF do
BEGIN
FDTBL9D.EDIT;
FDTBL9D.FieldByName('QTYTARGET').AsFLOAT := (FDTBL9D.FieldByName('QTY').AsFLOAT * FDTbl9BA.FieldByName('QTY').ASINTEGER);
FDTBL9D.FieldByName('TOTALCOST').AsFLOAT := roundto(FDTBL9D.FieldByName('COST').AsFLOAT * FDTbl9BA.FieldByName('QTY').ASINTEGER,-2);
tcost := tcost + FDTBL9D.FieldByName('TOTALCOST').AsCurrency;
try
FDTBL9D.Post;
EXCEPT
on E: Exception do
showmessage('Exception Raised MO ITEM Post with message : '+ #13#10 + E.message);
END;
FDTBL9D.Next;
END;
FDTBL9BA.EDIT;
if FDTbl9BA.FieldByName('QTY').ASINTEGER = 1 then
FDTBL9BA.FIELDBYNAME('COST').AsCurrency := tcost
ELSE
FDTBL9BA.FIELDBYNAME('COST').AsCurrency := ROUNDTO(tcost/FDTbl9BA.FieldByName('QTY').ASINTEGER,-4);
FDTBL9BA.FIELDBYNAME('TOTALCOST').AsCurrency := ROUNDTO(tcost,-2);
if MOBOMDATAGridDatabaseAdapter.DataLink.DataSet.State in [dsEdit] then
begin
MOBOMDATAGridDatabaseAdapter.DataLink.DataSet.Post;
LABEL9.Text := 'Status: Updated : '+AVALUE.ToString;
end;
END;
MOBOMDATAGrid.BeginUpdate;
MOBOMDATAGrid.ExpandNode(ACell.Row);
MOBOMDATAGrid.EndUpdate;
WOitemsDataGrid.UpdateCalculations;
end;
end;
end;
The above code is how I am handling it. If you see something please comment.