如何使dbgrid奇数行变红色,偶数行不变

解决方案 »

  1.   

    with Table1 do
      begin
        If RecNO Mod 2 <> 0 Then
        begin
          DBGrid1.Canvas.Font.Color := clGreen;
          DBGrid1.Canvas.Brush.Color := clWhite;
        end;
      end;
      
      DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      

  2.   

    放在DBGRID的DrawColumnCell事件里!
      

  3.   

    用DBGrid比較麻煩,同上
    如果你用wwDBGrid就好了!
    procedure TBaseBrowseForm.wwDBGrid1CalcCellColors(Sender: TObject;
      Field: TField; State: TGridDrawState; Highlight: Boolean; AFont: TFont;
      ABrush: TBrush);
    begin
    if wwDBGrid1.DataSource.DataSet.RecNo mod 2 <>0 then
        begin
          DBGrid1.Canvas.Font.Color := clred;
          DBGrid1.Canvas.Brush.Color := clWhite;
        end;
    end;