如何让当前行的颜色(该行的底色及字体颜色)发生改变?一般来说选中整行可以实现这个效果,当我要求是非选中整行时(即无论点该行的哪一格都要有这种效果)

解决方案 »

  1.   

    在DBGrid的OnDrawColumnCell事件中:type TMyGrid = class(TDBGrid);procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      with DBGrid1.Canvas do begin
        if DBGrid1.MouseCoord(Rect.Left+1, Rect.Top+1).Y = TMyGrid(DBGrid1).Row then begin
          Brush.Color := clRed;    // 背景色
          Font.Color := clWhite;   // 前景色
        end
        else begin
          Brush.Color := clWindow;
          Font.Color := clWindowText;
        end;
        DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
    end;