修改cxgrid的分组标题 delphi XE测试通过.
单元文件
unit Unit15;
interface
uses
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
end
end