如何控制DBGrid中每行颜色的控制,是实现颜色的隔行控制,不是根据记录的状态来控制

解决方案 »

  1.   

    在它的
    DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);中加入
     if ds.DataSet =aFee then
      begin
      if trim(AFee.FieldByName('IsFinish').AsString) ='1'  then
        DBGRID1.Canvas.Font.Color := clblack
      else if trim(AFee.FieldByName('IsFinish').AsString) ='0'  then
        DBGRID1.Canvas.Font.Color := clRed;  DBGRID1.DefaultDrawDataCell(Rect, Field, State);
      end;
      

  2.   

    定义一个在Private 中的整型变量i在OnDrawColumnCell写下:
    if i div2=0 then
      DBGrid1.Canvas.Brush.Color:=clRead
    else
      DBGrid1.Canvas.Brush.Color:=clWhite;
    DBGrid1.Canvas.FillRect(Rect);i:=i+i;
      

  3.   

    写错了
     
    div和2间有个空格
      

  4.   

    to lihao_ningxia(耗子) 
    没解决实质的问题,网格的颜色不是根据数据来更换的
      

  5.   

    procedure TForm_Main.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      with DBGrid1.Canvas do
      begin
        if 你的条件 then
          DBGrid1.Canvas.Brush.Color:= clBackground
        end;
       DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  6.   

    使用这个吧,我刚实验通过了
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      with DBGrid1.Canvas do
      begin
        if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then
          DBGrid1.Canvas.Brush.Color:= clBackground
        else DBGrid1.Canvas.Brush.Color := clOlive;
      end;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;