星期二, 8月 05, 2008

cxgrid分組加上共幾筆的資訊


//create呼叫
// 設定分組之群組資訊
SetCxGridSummaryItems(cxGDBTV1);

procedure TfmMain.SetCxGridSummaryItems(cxGDBTV: TcxGridDBTableView);
var
x: Integer;
sFormat :String;
begin
with cxGDBTV.DataController.Summary do
begin
BeginUpdate;
try
SummaryGroups.Clear;

DefaultGroupSummaryItems.BeginText := '{';
DefaultGroupSummaryItems.EndText := '}';

// Add summary group
with SummaryGroups.Add do
begin
// Add proposed grouping column(s)
// 即以這欄位作分組時會顯示summary items的資訊
for x:=1 to cxGDBTV.ColumnCount-1 do
begin
TcxGridTableSummaryGroupItemLink(Links.Add).Column := cxGDBTV.Columns[x-1];
end;
// Add summary items
sFormat := Format('共 %d 筆', [0]); // '共 0 筆'
with SummaryItems.Add as TcxGridDBTableSummaryItem do
begin
Kind := skCount; // 計算群組筆數
Position := spGroup;
Format := sFormat; // '共 0 筆'
end;
end;

{
// 增加寫出檔案大小統計功能
with SummaryGroups.Add do
begin
// Add proposed grouping column(s)
// 即以這欄位作分組時會顯示summary items的資訊
for x:=1 to cxGDBTV.ColumnCount-1 do
begin
TcxGridTableSummaryGroupItemLink(Links.Add).Column := cxGDBTV.Columns[x-1];
end;
// Add summary items
with SummaryItems.Add as TcxGridDBTableSummaryItem do
begin
//Column := cxGDBTV.GetColumnByFieldName('filesize');
//Column := cxGDBTV.GetColumnByFieldName('filesize'); //GetColumnByFieldName('cxGDBTV1filesize;
ItemLink := cxGDBTV.GetColumnByFieldName('filesize');
Kind := skSum;
Position := spFooter;
Format := 'TOTAL = 0';
end;
end;
//FooterSummaryItems.Add;
}
finally
EndUpdate;
end;
end;
end;