Technical Information Database
TI814D.txt How to handle text drawing in a TDBGrid
Category :Database Programming
Platform :All
Product :Delphi 1.0
Description:
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;
Reference:
7/16/98 4:33:54 PM
Last Modified: 01-SEP-99