当DBGrid的某行的某一个字段满足我的条件,我要在DBGrid中显示这一行为红色,应如何做,急

解决方案 »

  1.   

    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 thenDBGrid1.Canvas.Font.Color := clBlue;DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end;
      

  2.   

    ---- 在ColoredDBGrid1的onDRawColoredDBGrid事件中输入下列代码,设定由Wage(工资)来决定在ColoredDBGrid1各行的颜色。 
    procedure TForm1.ColoredDBGrid1 DRawColoredDBGrid 
    (Sender: TObject;  Field: TField; var Color: 
    TColor; var Font: TFont);
    Var
      p : Integer;
    begin
        p := Table1.FindField('wage').AsInteger;
      //取得当前记录的Wage字段的值。
        if(p < 500) then begin                 
    //程序将根据wage值设置各行的颜色。
          Color := clGreen;
          Font.Style := [fsItalic];      
    //不仅可以改变颜色,还可以改变字体
        end;
        if(p >= 500) And (p < 800) then
          Color := clRed;
         if(p >=800) then begin
          Color := clMaroon;
          Font.Style := [fsBold];
        end;
    end;
      

  3.   

    okgxs(一叶风铃) 第一次的回答更适合我要的,所以我给的分数更多