博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
myCxGrid
阅读量:6681 次
发布时间:2019-06-25

本文共 4027 字,大约阅读时间需要 13 分钟。

//author: cxg

//操作cxgrid

unit myCxGrid;

interface

uses

  SysUtils, ComCtrls, Forms, Messages, Windows, ExtCtrls, StdCtrls
  , Graphics, Controls, Dialogs, Classes,
  cxCustomData, cxGraphics,
  cxFilter, cxData, cxDataStorage, cxDBData, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGrid, cxGridExportLink
  , cxLookAndFeelPainters
  ;   

type

  TMyCxGrid = class(TObject)
    class procedure DrawIndicatorCell(
      Sender: TcxGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    class procedure DrawBackground(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
  end;

procedure ExpGridToXls(grid: TcxGrid);    //cxgrid操作

procedure CreateFooter(c: TcxGridDBTableView;
  const fieldList: string; typ: TcxSummaryKind);
procedure ShowLineNo(c: TcxGridDBTableView);

implementation

uses

  uLanguage
  ;

procedure ShowLineNo(c: TcxGridDBTableView);

begin
  c.OptionsView.Indicator := True;
  c.OptionsView.IndicatorWidth := 40;
  c.OnCustomDrawIndicatorCell := TMyCxGrid.DrawIndicatorCell;
  c.OnCustomDrawPartBackground := tmycxgrid.DrawBackground;
end;

procedure CreateFooter(c: TcxGridDBTableView;

  const fieldList: string; typ: TcxSummaryKind);
var
  i: Integer;
  f: TcxGridDBTableSummaryItem;
  l: TStringList;
begin
  l := TStringList.Create;
  l.DelimitedText := fieldList;
  l.Delimiter := ',';
  c.OptionsView.Footer := True;
  for i := 0 to c.ColumnCount - 1 do
  begin
    if l.IndexOf(c.Columns[i].DataBinding.FieldName) <> -1 then
    begin
      f := (c.DataController.Summary.FooterSummaryItems.Add) as TcxGridDBTableSummaryItem;
      f.FieldName := c.Columns[i].DataBinding.FieldName;
      f.Column := c.Columns[i];
      f.Kind := typ;
      case typ of
        skSum: f.Format := gethashstr('total');
        skCount: f.Format := gethashstr('count');
        skAverage: f.Format := gethashstr('average');
        skMin: f.Format := gethashstr('min');
        skMax: f.Format := gethashstr('max');
      end;
    end;
  end;
  l.Free;
end;

procedure ExpGridToXls(grid: TcxGrid);

var
  SaveDialog: TSaveDialog;
begin
  SaveDialog := TSaveDialog.Create(nil);
  with SaveDialog do
  begin
    Filter := 'excel|*.xls|html|*.html|xml|*.xml|text|.txt';
    if Execute then
    begin
      case FilterIndex of
        1: ExportGridToExcel(FileName, grid);
        2: ExportGridToHTML(FileName, grid);
        3: ExportGridToXML(FileName, grid);
        4: ExportGridToText(FileName, grid);
      end;
    end;
  end;
  SaveDialog.Free;
end;

{ TMyCxGrid }

class procedure TMyCxGrid.DrawBackground(

      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo is TcxGridGroupByBoxViewInfo then
  begin
    AViewInfo.Text:= GetHashStr('draggroup');
    ACanvas.FillRect(AViewInfo.Bounds);
  end; 
end;

class procedure TMyCxGrid.DrawIndicatorCell(Sender: TcxGridTableView;

  ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  var ADone: Boolean);
var
  AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
  ATextRect: TRect;
  AFont: TFont;
  AFontTextColor, AColor: TColor;
begin
  AFont := ACanvas.Font;
  AColor := clBtnFace;
  AFontTextColor := clWindowText;
  if (AViewInfo is TcxGridIndicatorHeaderItemViewInfo) then
  begin
    ATextRect := AViewInfo.Bounds;
    InflateRect(ATextRect, -1, -1);

    Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.Bounds,

      ATextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter,
      False, False, GetHashStr('lineno'), AFont, AFontTextColor, AColor);
    ADone := True;
  end;

  if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then

    Exit;
  ATextRect := AViewInfo.ContentBounds;
  AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
  InflateRect(ATextRect, -1, -1);

  if AIndicatorViewInfo.GridRecord.Selected then

    AFont.Style := ACanvas.Font.Style + [fsBold]
  else
    AFont.Style := ACanvas.Font.Style - [fsBold];

  Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,

    ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, vaCenter,
    False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
    AFont, AFontTextColor, AColor);
  ADone := True;
end;

end.

转载地址:http://amnao.baihongyu.com/

你可能感兴趣的文章
台州学院we are without brain 训练 计算几何
查看>>
Webpack 代码分离
查看>>
ssh下:系统初始化实现ServletContextListener接口时,获取spring中数据层对象无效的问题...
查看>>
extundelete
查看>>
powerviot install in sharepoint 2013
查看>>
javascript在我的工作的用法
查看>>
《告诉他们,我已乘白鹤去了》观后感——用生命换取信仰
查看>>
诡秘的“端口安全”功能
查看>>
市场活动课件:SQL Server 索引优化
查看>>
Linux程序包管理rpm命令的使用解析
查看>>
什么是证书颁发机构(CA)
查看>>
php-fpm定义成集群资源时报错解决方法
查看>>
FORM开发相关技术(二)
查看>>
实战DeviceIoControl 之一:通过API访问设备驱动程序
查看>>
MFC消息循环
查看>>
配置Spring数据源
查看>>
Jquery元素追加和删除
查看>>
QtWidget: 鼠标拖动窗口(没有标题栏时)
查看>>
数据挖掘
查看>>
Lightning Lessons 史上最蛋疼的英文题
查看>>