使得DBGrid1中某一个字段中的符合条件的内容为红色,不符合条件的为蓝色?在先给分...

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
      DataCol: Integer; Column: TColumn; State: TGridDrawState); 
    begin 
    if Table1.FieldByName('size').AsInteger >=40 then 
      begin 
      DBGrid1.Canvas.Font.Color := clRed; 
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 
      end else
    DBGrid1.Canvas.Font.Color := clblue; 
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 
    end;
    end;
      

  2.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
      DataCol: Integer; Column: TColumn; State: TGridDrawState); 
    begin 
    if DataCol=1 then  //第一列
    if Table1.FieldByName('size').AsInteger >=40 then 
      begin 
      DBGrid1.Canvas.Font.Color := clRed; 
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 
      end else
    DBGrid1.Canvas.Font.Color := clblue; 
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 
    end;
    end;