在ONDrawColumnCell事件这样写
inherited;
with DBGrid1 do
begin
if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
Begin
// Canvas.Font.Color :=ClYellow;
// Canvas.Brush.Color :=ClNavy;
End
else
begin
if DataSource1.DataSet.RecNo mod 2<>0 then
Canvas.brush.Color :=cl3dlight
else
Canvas.brush.Color :=clinfobk;
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State); //这行是关键
end;
设置全局变量 i:boolean;
在ONDrawColumnCell事件这样写
if i then
DBGrid1.Canvas.Brush.Color:=clBtnFace
else
DBGrid1.Canvas.Brush.Color:=clRed;
i:=not i;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.DefaultDrawColumnCell (Rect,DataCol,Column,State);