自画cxGrid表格(类封装)

unit UnitDevExpressVCLCustom;

interface

uses
  cxGrid, cxGridTableView, cxGridDBBandedTableView, Winapi.Windows, System.SysUtils, System.Variants, cxClasses,
  System.Classes, Vcl.Graphics, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters, cxCustomData, cxTextEdit, cxEdit,
  cxCheckBox, Vcl.Controls, Vcl.Dialogs, cxGridDBTableView, cxGridCustomTableView, cxGridCustomView;

type
  TMyCxGrid = class(TCxGrid)
  private
    { Private declarations }
    //变量
    cxGridDBTableView: TcxGridDBTableView;
    //储存过程和函数
    procedure CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
  public
    { Public declarations }
  end;

procedure IniMyCxGrid(cxGridDBBandedTableView: TcxGridDBBandedTableView; cxGridDBTableView: TcxGridDBTableView);

implementation

procedure TMyCxGrid.CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo;
  var ADone: Boolean);
var
  I: Integer;
  lMaxRow: Integer;
  Rect1: TRect;
  ABorder: TcxBorder;
begin
  ACanvas.FillRect(AViewInfo.Bounds);
  ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter);
  //计算最多画多少行
  lMaxRow := AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Bottom - AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Top mod AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top + 2;
  if AViewInfo.GridRecord.Index = cxGridDBTableView.ViewData.RecordCount - 1 then
    begin
      for i := cxGridDBTableView.ViewData.RecordCount + 1 to lMaxRow do
        begin
          //画表格
          Rect1.Top := AViewInfo.Bounds.Top - 1 + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView.ViewData.RecordCount);
          Rect1.Bottom := AViewInfo.Bounds.Bottom + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView.ViewData.RecordCount);
          Rect1.Left := AViewInfo.Bounds.Left - 1;
          Rect1.Right := AViewInfo.Bounds.Right + 1;

          if AViewInfo.GridView.Styles.Content <> nil then
            ACanvas.Brush.Color := AViewInfo.GridView.Styles.Content.Color
          else
            ACanvas.Brush.Color := clWhite;

          if (i mod 2) = 0 then
            if AViewInfo.GridView.Styles.ContentOdd <> nil then
              ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentOdd.Color
            else if AViewInfo.GridView.Styles.ContentEven <> nil then
              ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentEven.Color;

          ACanvas.FillRect(Rect1);
          ACanvas.Brush.Color := AViewInfo.BorderColor[ABorder];
          ACanvas.FrameRect(Rect1);
          AViewInfo.GridViewInfo.Painter.ExcludeFromBackground(Rect1);
        end;
    end;
end;

{-------------------------------------------------------------------------------
  作者:      曾聪
  日期:      2013.10.07
  过程名:    IniMyCxGrid
  功能:      调用TMyCxGrid相关函数初始化CxGrid
  参数:      
  返回值:    无
  说明:
-------------------------------------------------------------------------------}

procedure IniMyCxGrid(cxGridDBTableView: TcxGridDBTableView);
var
  MyCxGrid: TMyCxGrid;
begin
  MyCxGrid := TMyCxGrid.Create(nil);;
  MyCxGrid.cxGridDBTableView := cxGridDBTableView;
  if cxGridDBTableView <> nil then
    begin
      cxGridDBTableView.OnCustomDrawCell := MyCxGrid.CustomDrawCell; //调用自画表格函数
      cxGridDBTableView.Site.Cursor := crHandPoint; //改变鼠标手势
    end;
end;

end.


procedure TFormMainOperation.FormCreate(Sender: TObject);
begin
  IniMyCxGrid(cxgrddbtv1, nil);
end;


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CxGrid是一个非常强大和灵活的表格控件,可以用于显示和编辑数据。它具有许多吸引人和实用的功能,使得它成为选择grid的理想之一。 首先,CxGrid可以提供多种多样的数据显示选项。它可以以表格的形式展示数据,这使得数据更加清晰和易于阅读。此外,CxGrid还可以将数据以树形结构展示,使得用户可以更好地组织和管理数据。另外,CxGrid还支持多级分组和排序,可以根据某一列或者多列进行排序和分组,方便用户快速查找和筛选数据。 其次,CxGrid具有丰富的数据编辑功能。用户可以通过单击编辑单元格来修改数据,也可以直接在编辑框中输入新的值。此外,CxGrid还支持复选框、下拉框、日期选择等不同型的数据输入和编辑方式。对于需要批量编辑数据的情况,CxGrid还可以启用批量编辑模式,使得用户可以同时修改多行数据。 另外,CxGrid还提供了一些高级功能,如过滤器和表达式编辑器。用户可以根据特定的条件来过滤数据,只显示符合条件的数据。同时,用户还可以使用表达式编辑器自定义计算列,根据特定的表达式对数据进行计算和处理。 此外,CxGrid还允许用户对表格进行自定义布局和外观设置。用户可以自由调整列的顺序和宽度,设置列的对齐方式和格式。同时,CxGrid提供了丰富的皮肤和样式选项,可以让用户根据自己的喜好来美化表格外观。 综上所述,CxGrid具有丰富的功能和灵活的设计,使得它成为选择grid的理想之一。无论是数据展示还是数据编辑,CxGrid都能满足用户的需求,并提供良好的用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值