http://www.cnblogs.com/lance2088/archive/2008/08/21/1272976.html定义个子类MyDBGrid继承TDBGrid,以提供访问父类保护成员的接口。
type
  MyDBGrid=class(TDBGrid)
  private  public
    function GetRow:integer;
    function IsCurrent:boolean;
end; function MyDBGrid.GetRow: integer;
begin
  result:=row;
end;function MyDBGrid.IsCurrent: boolean;
begin
  result:=(DataLink.ActiveRecord=row-1);
end; 判断是否是当前行。type
  TGlobal=class      class function IsCurrentRow(AMyDBGrid:MyDBGrid):boolean;end;
class function TGlobal.IsCurrentRow(AMyDBGrid: MyDBGrid): boolean;
begin
  result:=AMyDBGrid.IsCurrent;
end; 在DrawColumnCell事件中。 procedure TFormMain.MyDBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if TGlobal.IsCurrentRow(MYDBGrid(Sender))     begin
        (Sender as TDBGrid).Canvas.Brush.Color :=$000080FF;    end
    else
    begin
      if (Sender as TDBGrid).DataSource.DataSet.RecNo  mod 2 =0 then
        (Sender as TDBGrid).Canvas.Brush.Color :=rgb(246,246,246);   //$00F3F3F3; //定义背景颜色
    end;
    (Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);end; 效果:

解决方案 »

  1.   

    很多人问如何设置DBGrid当前行的颜色,这是一个解决的办法。
      

  2.   

    我用DBGRIDEH 
    用到(Sender as TDBGridEH).DefaultDrawColumnCell(Rect,DataCol,Column,State);  这个时出错,提示类型不
      

  3.   

    我不想继续回复这个帖子了,很无聊。http://www.google.com/search?client=opera&rls=en&q=DrawColumnCell&sourceid=opera&ie=utf-8&oe=utf-8
      

  4.   

    你不如直接回复  www.google.com在DrawColumnCell事件里 如何能知道当前画的是哪一行?
      

  5.   

    你不如直接回复 www.google.com
      

  6.   

    呵呵。在DrawColumnCell事件中如何知道当前画的是哪行?