大虾,你那个dbgrid.columns[i].color:=clred; 是使指定的某列的颜色变成红色,我是指对查询到的“某行”施加颜色,(即某条记录施加颜色)谢谢!!

解决方案 »

  1.   

    响应OnDrawColumnCell事件,例如下面代码摘自我过去开发的代码,供参考。
    procedure TSelectForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    var
      Value: String;
      with (Sender as TDBGrid),(Sender as TDBGrid).Canvas do
      begin
        if not (gdSelected in State) then
          case StrToInt((DataSource.DataSet)['dydj']) of
            220: Font.Color := clRed;
            110: Font.Color := clNavy;
            35:  Font.Color := clMaroon;
            10:  Font.Color := clBlack;
          else
            Font.Color := clBlack;
          end
        else
        begin
          Font.Color := clWhite;
          Brush.Color := clBlack;
        end;
        FillRect(Rect);
        Value := '';
        if Assigned(Column.Field) then
          Value := Column.Field.DisplayText;
        TextOut(Rect.Left+3, Rect.Top+1, Value);
    end;