在DBgrid中怎样才能把不满足条件的记录用颜色标示出来.

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if (Table1.FieldByName('CustNo').AsInteger = 3) or
         (Table1.FieldByName('CustNo').AsInteger = 5) then
        DBGrid1.Canvas.Font.Color := clBlue;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  2.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if (Table1.FieldByName('CustNo').AsInteger = 3) or
         (Table1.FieldByName('CustNo').AsInteger = 5) then
        DBGrid1.Canvas.Font.Color := clBlue;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  3.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if (Table1.FieldByName('CustNo').AsInteger = 3) or
         (Table1.FieldByName('CustNo').AsInteger = 5) then
        DBGrid1.Canvas.Font.Color := clBlue;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  4.   


     行颜色除了上朋友用的“DBGrid1.Canvas.Font.Color := clBlue;”字体颜色外,还可以使用“DBG_pand.Canvas.Brush.Color :=clWindow ;”行背景颜色;
      

  5.   

    DBGrid1DrawColumnCell事件。
    sex字段为女的,字体颜色为红色,其它的为蓝色:
     if AdoTable1.FieldByName('sex').Asstring = '女' then
      DBGrid1.Canvas.Font.Color := clRed
     else
      DBGrid1.Canvas.Font.Color := clBlue;
     DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      

  6.   

    完整版
    procedure Tfrmincrease.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    var i :integer;
    begin
    if gdSelected in State then Exit;//定义表头的字体和背景颜色:for i :=0 to (Sender as TDBGrid).Columns.Count-1 do
    begin
      (Sender as TDBGrid).Columns[i].Title.Font.Name :='宋体';      //字体
      (Sender as TDBGrid).Columns[i].Title.Font.Size :=9;           //字体大小
      (Sender as TDBGrid).Columns[i].Title.Font.Color :=$000000ff;  //字体颜色
      (Sender as TDBGrid).Columns[i].Title.Color :=$000aeeff;       //背景色
    end;//隔行改变网格背景色:
    if AdoQuery1.RecNo mod 2 = 0 then
      (Sender as TDBGrid).Canvas.Brush.Color := clCream   //clInfoBk            //定义背景颜色
    else
      (Sender as TDBGrid).Canvas.Brush.Color := RGB(221, 255, 255); //定义背景颜色
    DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    //定义网格线的颜色:
    with (Sender as TDBGrid).Canvas do            //画 cell 的边框
    begin
      Pen.Color := clBtnFace;//$00ff0000;         //定义画笔颜色
      MoveTo(Rect.Left, Rect.Bottom);             //画笔定位
      LineTo(Rect.Right, Rect.Bottom);            //画蓝色的横线
      Pen.Color := clBtnFace;//$0000ff00;         //定义画笔颜色
      MoveTo(Rect.Right, Rect.Top);               //画笔定位
      LineTo(Rect.Right, Rect.Top);               //画竖线
    end;end;
      

  7.   

    http://218.56.11.178:8020/web/index.aspx->下载基地->例程-数据库/报表->控制数据表每行的颜色控制数据表每行的颜色
      

  8.   

    用odd判断行号,奇偶不同则显示不同的北景色