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;

    效果:

     

     

  • 相关阅读:
    DS博客作业05--查找
    DS博客作业04--图
    DS博客作业03--树
    DS博客作业02--栈和队列
    C博客作业05-指针
    C语言——数组博客作业
    c语言博客3—函数
    循环结构博客
    c语言博客,顺序与分支结构
    Java面向对象课程设计——购物车
  • 原文地址:https://www.cnblogs.com/lance2088/p/1272976.html
Copyright © 2011-2022 走看看