Cxgrid控件分组标题的修改,该怎么处理
Cxgrid控件分组标题的修改
如何更改通过Cxgrid控件进行分组后显示的标题. 之前问过是Ehlib,但是没实现,帖子已结.
例图

比如更改红框那一行的分组标题,在后面添加任意文本或数据.
修改为: Company:Action Club (6) 俱乐部
代码比如:原分组标题+任意字符串
------解决方案--------------------
满足了lz需求
delphi XE下测试通过
如何更改通过Cxgrid控件进行分组后显示的标题. 之前问过是Ehlib,但是没实现,帖子已结.
例图
比如更改红框那一行的分组标题,在后面添加任意文本或数据.
修改为: Company:Action Club (6) 俱乐部
代码比如:原分组标题+任意字符串
------解决方案--------------------
满足了lz需求
delphi XE下测试通过
{示例说明:
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;