Previously with the default DBGrid I could alter the value of a cell without altering the data in a database with the following code.
procedure TEMRForm.DBGridCDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.FieldName = 'START_DATE' then
begin
DBGridC.Canvas.FillRect(Rect);
DBGridC.Canvas.TextOut(Rect.Left+2,Rect.Top+2,Column.Field.Text + ' *');
end;
end;
Which worked great, but I am having trouble implementing this same kind of functionality on a cxgrid. Here is my current code which shows no indication of the cell value being changed.
procedure TEMRForm.cxGridCDBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
ARect: Trect;
begin
ARect := AViewInfo.Bounds;
if AViewInfo.Item.Caption = 'Start Date' then
begin
ACanvas.FillRect(ARect);
ACanvas.TextOut(ARect.Left+2,ARect.Top+2,TableC.FieldByName('START_DATE').AsString+' *');
end;
end;
I think the reason why you don't see the drawning done in cxGridCDBTableView1CustomDrawCell()
is because you don't set the ADone
parameter to true
- thus the default painting will "cancel" (overpaint) your's.
However, I think the right way to achieve what youre after is to use column's events OnGetDisplayText
and OnGetContentStyle
(the later event is subproperty of Styles, ie Column.Styles.OnGetContentStyle
).