procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
const
AlignFlags : array [TAlignment] of Integer =
( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX );
var
Value: string;
RecColor:TColor;
R:TRect;
dbg:TDBGrid;
cs:TCanvas;
begin
Value := '';
if Assigned(Column.Field) then
Value := Column.Field.DisplayText;
dbg:=Sender as TDBGrid;
if gdselected in State then
RecColor:=clHighlight
else if dbg.DataSource.DataSet.RecNo mod 2 =0 then
RecColor:=$00C0E0E0
else
RecColor:=$00E8FFFF;
with Rect do
R:= Classes.Rect(Left+2,Top+ 2, Right-2, Bottom);
dbg.Canvas.Brush.Color:=RecColor;
dbg.Canvas.FillRect(Rect);
DrawText(dbg.Canvas.Handle, PChar(Value), Length(Value), R,
AlignFlags[Column.Alignment]);
cs:=TCanvas.Create;
cs.Handle:=GetDC(dbg.Handle);
try
cs.FrameRect(Rect);
finally
ReleaseDC(dbg.Handle,cs.Handle);
cs.Free;
end;
end;
end;