如何让DBGrid中的数据奇数行和偶数行的颜色不一样

解决方案 »

  1.   

    procedure TForm_Main.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:= clWhite;
      end;
       DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  2.   

    去google用ondrawcolumncell,delphi做关键字搜索