想在dbgrid里实现根据某个字段的值而使得那一行的纪录的字体的颜色不同,如何实现???

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    var
      i,j:integer;
    begin
      i:=form1.DBGrid1.DataSource.DataSet.RecordCount;
      if i>0 then
      begin
        for j:=0 to i-1 do
        begin
          if form1.DBGrid1.DataSource.DataSet.FieldValues['姓名']='ert' then
          begin
            form1.DBGrid1.Canvas.Brush.Color:=clred;
            form1.DBGrid1.Canvas.Pen.Mode:=pmmask;
            if not form1.DBGrid1.SelectedRows.CurrentRowSelected then
              form1.DBGrid1.Brush.Color:=claqua;
            form1.DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
          end;
        end;
      end;
    end;
      

  2.   

    忘了加上
    form1.DBGrid1.DataSource.DataSet.Next;