问问题之前先搜索一下吧,你这个问题至少有一千个人问过了也许还不止,procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Dbgrid1.DataSource.DataSet.RecNo mod 2=0 then begin DBGrid1.Canvas.Brush.Color:=$00eaeaea; DBGrid1.Canvas.FillRect(rect); DBGrid1.Canvas.font.color:=clblack; end else begin DBGrid1.Canvas.Brush.Color:=clwhite; DBGrid1.Canvas.FillRect(rect); DBGrid1.Canvas.font.color:=clblack; end; if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then begin DBGrid1.Canvas.Brush.Color:=clinfobk; DBGrid1.Canvas.FillRect(rect); DBGrid1.Canvas.font.color:=clblack; end; DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
DBGrid 的 DrawColumnCell 事件procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with DBGrid1.Canvas do begin if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then DBGrid1.Canvas.Brush.Color:= clBackground //偶数行颜色 else DBGrid1.Canvas.Brush.Color := clOlive; //奇数行颜色 end; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin if Dbgrid1.DataSource.DataSet.RecNo mod 2=0 then
begin
DBGrid1.Canvas.Brush.Color:=$00eaeaea;
DBGrid1.Canvas.FillRect(rect);
DBGrid1.Canvas.font.color:=clblack;
end
else
begin
DBGrid1.Canvas.Brush.Color:=clwhite;
DBGrid1.Canvas.FillRect(rect);
DBGrid1.Canvas.font.color:=clblack;
end;
if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
begin
DBGrid1.Canvas.Brush.Color:=clinfobk;
DBGrid1.Canvas.FillRect(rect);
DBGrid1.Canvas.font.color:=clblack;
end;
DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1.Canvas do
begin
if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then
DBGrid1.Canvas.Brush.Color:= clBackground //偶数行颜色
else DBGrid1.Canvas.Brush.Color := clOlive; //奇数行颜色
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;