如何在DBGrid中,让指定的CELL格显示指定的背景色,字体,文字颜色?

解决方案 »

  1.   

    用onDrawDataCell事件,如下:
    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
      if Field.Text='2' then
        DBGrid1.Canvas.brush.Color := clred;
      DBGrid1.DefaultDrawDataCell(rect,field,state);
    end;
    哥们,分有点少啊
      

  2.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if (form1.Table1.RecNo=1) and (datacol=2) then
      begin
        form1.DBGrid1.Canvas.Brush.Color:=clred;
        form1.DBGrid1.Canvas.Font.Size:=10;
        form1.DBGrid1.Canvas.Font.Name:='楷体';
        form1.DBGrid1.Canvas.Font.Color:=clblue;
      end;
      form1.DBGrid1.Canvas.Pen.Mode:=pmmask;
      form1.DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;
      

  3.   

    呵呵, 来晚了
    同意楼上俩位说的 !~~~
    但是存在 这样一个问题,请俩位指点
    如果我需要在一个dbgrid中让不同的记录显示不同的记录
    怎么做 ?
    谢谢!~~~