unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, DBTables;
type
TCustomDBGridCracker=class(TCustomDBGrid);//注意,要加入这句
TForm1 = class(TForm)
Table1: TTable;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with TCustomDBGridCracker(sender) do begin
if DataLink.ActiveRecord =Row-1 then // 如果被选中
begin
Canvas.Brush.Color :=clred; //选中时颜色
canvas.Font.Color :=clyellow; //选中的字体颜色
// canvas.Font.Style:=[fsBold]; //选中时的字体
//canvas.Font.Size :=10;
end
else begin //没有被选中时
{ if (DataSource.DataSet.RecNo mod 2)=0 then //可以试下加入这句,
canvas.brush.color:=$00FFF0E0 else } //会有什么效果,肯定会令你满意!
canvas.brush.color:=clwindow;
//canvas.Font.Style:=[];
//canvas.Font.Size :=9;
canvas.Font.Color :=clblack;
end;
defaultdrawcolumncell(Rect,DataCol,Column,State);
end;
end;
end.