?

解决方案 »

  1.   

    在StringGrid中,我是这样处理的,当然,我只是让某几列不一样,参照一下即可。
    void __fastcall TMainFrm::StringGrid1DrawCell(TObject *Sender, int ACol,
          int ARow, TRect &Rect, TGridDrawState State)
    {
       //这儿你根据条件设定颜色,
        if ((ACol%2==1) && ARow!=0) {
            StringGrid1->Canvas->Brush->Color = clWhite;
            StringGrid1->Canvas->FillRect(Rect); //用上面设定的颜色填充
        }    StringGrid1->Canvas->TextRect(Rect, Rect.Left+2,
            Rect.Top+2, StringGrid1->Cells[ACol][ARow]);}
      

  2.   

    procedure DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      if 条件1 then
      begin
        DBGrid1.Canvas.Brush.Color:=clYellow; //背景色为黄色
        DBGrid1.Canvas.Font.Color := clRed; 
      end
      else
        if 条件2 then
        begin
          DBGrid1.Canvas.Brush.Color:=clSkyBlue; //背景色为天蓝色
          DBGrid1.Canvas.Font.Color := clPurple;
        end
        else
          DBGrid1.Canvas.Font.Color:=clGreen;//默认的
      DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);//这句一定要加上
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      with StringGrid1 do
        with Canvas do
        begin
          if (ARow=Row)and(ACol>=FixedCols) then
            Brush.Color:=clRed
          else
            if (ARow>=FixedRows)and(ACol>=FixedCols) then Brush.Color:=clWhite;
          FillRect(Rect);
        end;end;end.
      

  4.   

    但我现在发现一个问题,当把DBGrid中Option->dgRowSelect设为True时,被设置过Brush的行将无法被选择(没有显示焦区颜色),不知该如何解决!