在DBGridEh表格控件中怎么实现将当前正在编辑某行资料用其它的背景颜色显示?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, DB, ADODB, DBGridEh;type
      TCustomDBGridCracker=class(TCustomDBGridEh);//注意,要加入这句
      TForm1 = class(TForm)
        DataSource1: TDataSource;
        ADOConnection1: TADOConnection;
        ADOQuery1: TADOQuery;
        DBGridEh1: TDBGridEh;
        procedure DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect;
          DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
           with TCustomDBGridCracker(sender) do begin
               if DataLink.ActiveRecord =Row-1 then  // 如果被选中
               begin
                   Canvas.Brush.Color :=clred;      //选中时颜色
                   canvas.Font.Color :=clyellow;    //选中的字体颜色
                  // canvas.Font.Style:=[fsBold];   //选中时的字体
                  //canvas.Font.Size :=10;
               end
               else begin                          //没有被选中时             { if (DataSource.DataSet.RecNo mod 2)=0 then  //可以试下加入这句,
                  canvas.brush.color:=$00FFF0E0  else }       //会有什么效果,肯定会令你满意!              canvas.brush.color:=clwindow;
                  //canvas.Font.Style:=[];
                  //canvas.Font.Size :=9;
                  canvas.Font.Color :=clblack;
               end;
            defaultdrawcolumncell(Rect,DataCol,Column,State);
            end;
    end;end.