不想使用第三方控件,怎么能控制DBGrid的字体颜色呢?
我响应OnDrawColumnCell和OnDrawDataCell事件,虽然能分色显示,但DbGrid的刷新好像出了问题,光标不能定位到前几条记录!
(我想改变字体颜色,而不是背景或选中后的颜色)

解决方案 »

  1.   

    //oncustomdrawcell事件写
    if ASelected then afont.Color:=clred;     //选中的栏的字体设为红色
     scheck:=ANode.Values[dxDBGrid1status.Index]; //dxdbgrid1status为某一个指定字段
     if not VarIsNull(scheck) then
      if scheck = '1' then            //这段为指定值的判定,如果为1把这一行定义为白颜色
                  
        AColor := clWhite
       else
        acolor:=clInfoBk;
      

  2.   

    楼上老兄,我用的是delphi5,没有oncustomerdrawcell事件啊?
      

  3.   

    OnDrawColumnCell事件中你要
    Dbgrid1.Canvas.font.color:=clGreen;
      

  4.   

    下面的程序是我经常在开发时使用的的
    供各位大虾参考:
    procedure Tresultshowfrm.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
    with DBGrid1.Canvas do
    begin
    if datamodule1.adoq_sqdj.FieldByName('bgrq').AsDateTime=date() then
     begin
      brush.Color:=clRed;
      font.Color:=clWhite;
     end;
    DBGrid1.DefaultDrawDataCell(rect,column.Field,state);
    end;
    end;
      

  5.   

    这样可以做到按列分色
    dbgird.Columns[i].Font.color:=clBackground;//蓝色
                                  clgreen;     //绿色
    还有很多颜色,自己看看;
      

  6.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     with DBGrid1 do
     if datasource.dataset.fieldbyname('Flag_js').asboolean=true then
     begin
       Canvas.font.color:=clblue;//如果条件为真,则字体颜色为蓝色 
       DefaultDrawColumnCell(rect,datacol,column,state);
     end;
    end;