2,495
社区成员
发帖
与我相关
我的任务
分享
{示例说明:
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;