研究一下以下的代码,你就可以写出满足你的要求的TDBGridEx了。
其主要是对OnDrawCell事件进行处理......
还不能搞定的话,拿我头去......
type 
  TMyDBGrid = class(TDBGrid) 
  protected 
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGri
dDrawState); override; 
    procedure Scroll(Distance: Integer); override; 
  end; implementation procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState
: TGridDrawState); 
var 
  bmp: TBitmap; 
begin 
  inherited DrawCell(ACol, ARow, ARect, AState); 
  if ((ARow mod 2)<>0) and (ACol<>0) then 
  begin 
    bmp := TBitmap.Create; 
    try 
      bmp.Width := ARect.Right - ARect.Left; 
      bmp.Height:= ARect.Bottom- ARect.Top; 
      BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, 
        Canvas.Handle, ARect.Left, ARect.Top, SRCCOPY); 
      bmp.TransparentMode := tmAuto; 
      bmp.Transparent := True; 
      Canvas.Brush.Color := clTeal; 
      Canvas.FillRect(ARect); 
      Canvas.Draw(ARect.Left, ARect.Top, bmp); 
    finally 
      bmp.Free; 
    end; 
  end; 
end; procedure TMyDBGrid.Scroll(Distance: Integer); 
begin 
  inherited Scroll(Distance); 
  Repaint; 
end; 

解决方案 »

  1.   

    可以使用以下属性
    dbgrid1.canvas.font.color:=ckgreen;
      

  2.   

    to ERealTime(平平常常):
    在DBGRID的事件中怎么没有OnDrawCell事件啊?
      

  3.   

    动态更新DBGrid的颜色
       例如,如果一个城市的人口大于200万,我们就让它显示为蓝色。使用的控件事件为DBGrid.OnDrawColumeCell: 
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if Table1.FieldByName('Population').AsInteger > 20000000 then
         DBGrid1.Canvas.Font.Color := clBlue;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;