zoukankan      html  css  js  c++  java
  • 设置DBGrid当前行的颜色


    定义个子类MyDBGrid继承TDBGrid,以提供访问父类保护成员的接口。
    type
      MyDBGrid=class(TDBGrid)
      private

      public
        function GetRow:integer;
        function IsCurrent:boolean;
    end;

     


    function MyDBGrid.GetRow: integer;
    begin
      result:=row;
    end;

    function MyDBGrid.IsCurrent: boolean;
    begin
      result:=(DataLink.ActiveRecord=row-1);
    end;

    判断是否是当前行。

    type
      TGlobal=class

          class function IsCurrentRow(AMyDBGrid:MyDBGrid):boolean;

    end;

    class function TGlobal.IsCurrentRow(AMyDBGrid: MyDBGrid): boolean;
    begin
      result:=AMyDBGrid.IsCurrent;
    end;

     

    在DrawColumnCell事件中。

     

    procedure TFormMain.MyDBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if TGlobal.IsCurrentRow(MYDBGrid(Sender)) 

        begin
            (Sender as TDBGrid).Canvas.Brush.Color :=$000080FF;

        end
        else
        begin
          if (Sender as TDBGrid).DataSource.DataSet.RecNo  mod 2 =0 then
            (Sender as TDBGrid).Canvas.Brush.Color :=rgb(246,246,246);   //$00F3F3F3; //定义背景颜色
        end;
        (Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);

    end;

    效果:

     

     

  • 相关阅读:
    文件系统
    Java的日志模块
    SQL Server 的索引结构实例
    SQL索引优化
    索引最佳实践
    SQL优化基础 使用索引(一个小例子)
    v使用索引的注意事项及常见场景、案例
    使用索引的注意事项及常见场景、案例
    SQL性能优化十条经验
    如何使用JVisualVM进行性能分析
  • 原文地址:https://www.cnblogs.com/lance2088/p/1272976.html
Copyright © 2011-2022 走看看