修改cxgrid的分組標題_cxgrid

來源:互聯網
上載者:User

修改cxgrid的分組標題   delphi XE測試通過.

單元檔案

unit Unit15;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,  cxStyles, dxSkinsCore, dxSkinCoffee, dxSkinscxPCPainter, cxCustomData,  cxFilter, cxData, cxDataStorage, cxEdit, cxGridCustomTableView,  cxGridTableView, cxGridBandedTableView, cxGridCustomView, cxClasses,  cxGridLevel, cxGrid;type  TForm15 = class(TForm)    cxgrdlvlGrid1Level1: TcxGridLevel;    cxgrd1: TcxGrid;    cxgrdbndtblvw: TcxGridBandedTableView;    cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column1: TcxGridBandedColumn;    cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column2: TcxGridBandedColumn;    cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column3: TcxGridBandedColumn;    procedure cxgrdbndtblvwCustomDrawGroupCell(      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;      AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean);  private    { Private declarations }  public    { Public declarations }  end;var  Form15: TForm15;implementation{$R *.dfm}{樣本說明:cxgrdbndtblvw : cxgrid的view名稱  含兩列  company, type}procedure TForm15.cxgrdbndtblvwCustomDrawGroupCell(  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;  AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean);var  FBounds: TRect;  sGroupName: string;            //分組行顯示的標題  i, iChildCount: Integer;begin  iChildCount := 0;  //獲得當前分組的下級數量  for i := 0 to cxgrdbndtblvw.DataController.RecordCount - 1 do  begin    if VarToStr(AViewInfo.GridRecord.Values[0]) = VarToStr(cxgrdbndtblvw.DataController.Values[i, 0]) then    begin      inc(iChildCount);      sGroupName := cxgrdbndtblvw.DataController.Values[i, 1];      //取type列的名字作為分組列名的一部分    end;  end;  //格式化分組行  sGroupName := Format('>> %s:%s(%d)%s', [    cxgrdbndtblvw.GroupedColumns[0].Caption,    AViewInfo.GridRecord.Values[0],    iChildCount,    sGroupName  ]);  //列印分組行  FBounds := AViewInfo.Bounds;  ACanvas.FillRect(FBounds);  OffsetRect(FBounds, 25, 0);  ACanvas.Font.Style := [fsBold];  ACanvas.DrawTexT(sGroupName, FBounds, cxAlignLeft or cxAlignVCenter or cxDontClip);  ADone := True;end;end.


表單檔案

object Form15: TForm15  Left = 0  Top = 0  Caption = 'Form15'  ClientHeight = 559  ClientWidth = 696  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -12  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  PixelsPerInch = 106  TextHeight = 14  object cxgrd1: TcxGrid    Left = 24    Top = 16    Width = 649    Height = 473    TabOrder = 0    object cxgrdbndtblvw: TcxGridBandedTableView      NavigatorButtons.ConfirmDelete = False      NavigatorButtons.First.Visible = True      NavigatorButtons.PriorPage.Visible = True      NavigatorButtons.Prior.Visible = True      NavigatorButtons.Next.Visible = True      NavigatorButtons.NextPage.Visible = True      NavigatorButtons.Last.Visible = True      NavigatorButtons.Insert.Visible = True      NavigatorButtons.Append.Visible = False      NavigatorButtons.Delete.Visible = True      NavigatorButtons.Edit.Visible = True      NavigatorButtons.Post.Visible = True      NavigatorButtons.Cancel.Visible = True      NavigatorButtons.Refresh.Visible = True      NavigatorButtons.SaveBookmark.Visible = True      NavigatorButtons.GotoBookmark.Visible = True      NavigatorButtons.Filter.Visible = True      DataController.Summary.DefaultGroupSummaryItems = <>      DataController.Summary.FooterSummaryItems = <>      DataController.Summary.SummaryGroups = <        item          Links = <>          SummaryItems = <            item              Column = cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column1            end>        end>      DataController.Data = {        E90000000F00000044617461436F6E74726F6C6C657231030000001200000054        6378537472696E6756616C75655479706512000000546378537472696E675661        6C75655479706512000000546378537472696E6756616C756554797065030000        00445855464D540000040000007400650073007400000200000079728A6B0001        0000003100445855464D5400000B00000041006300740069006F006E00200043        006C00750062000003000000F14F504EE89000010000003200445855464D5400        000B00000041006300740069006F006E00200043006C00750062000003000000        F14F504EE89000010000003100}      OnCustomDrawGroupCell = cxgrdbndtblvwCustomDrawGroupCell      Bands = <        item        end>      object cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column1: TcxGridBandedColumn        Caption = 'Company'        Width = 93        Position.BandIndex = 0        Position.ColIndex = 0        Position.RowIndex = 0      end      object cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column2: TcxGridBandedColumn        Caption = 'Type'        Position.BandIndex = 0        Position.ColIndex = 1        Position.RowIndex = 0      end      object cxgrdbndclmncxgrdbndtblvwcxgrd1BandedTableView1Column3: TcxGridBandedColumn        Caption = 'num'        Width = 93        Position.BandIndex = 0        Position.ColIndex = 2        Position.RowIndex = 0      end    end    object cxgrdlvlGrid1Level1: TcxGridLevel      GridView = cxgrdbndtblvw    end  endend


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.