2815:How to handle text drawing in a TDBGrid
KEYWORDS: dbgrid tdbgrid grid draw ondrawdatacell ondrawcell color text AREA:
The following method can be used as the event handler for a
TDBGrid.OnDrawDataCell event. This method demonstrates how
to paint the text in one column a different color than the
rest of the text in the grid.
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
{ NOTE: DefaultDrawing propery of Grid(s) must be set to False }
begin
{ if field name is "NAME" }
if Field.FieldName = 'NAME' then
{ change font color to red }
(Sender as TDBGrid).Canvas.Font.Color := clRed;
{ draw text in the grid }
(Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2,
Field.AsString);
end;
TI