那位知道怎样按DBGRID中的一些条件来改变每一行的颜色??
 例如:按性别,当性别字段为“男”时,那条记录的底色或字的颜色为蓝色
               当性别字段为“女”时,那条记录的底色或字的颜色为红色
 
       或者在该条记录有其他方式的标记,以区别其他记录??不知道大家看明白了吗??

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if Table1.FieldByName('xxx').AsInteger >xx then     //改变字体颜色
      begin
      DBGrid1.Canvas.Font.Color := clRed;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;  if Table1.FieldByName('xxx').AsInteger >=xx then     //改变行颜色
      begin
      DBGrid1.Canvas.Brush.Color := clRed;
      DBGrid1.FillRect(Rect);
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
    end;