动态生成TcxGridDBTableView的列及页脚的合计栏

var
 i   : Integer;
 cl  : TcxGridDBColumn;
begin
 Screen.Cursor :=  crHourGlass;
 cxtvMaster.BeginUpdate;
 try
   cxtvMaster.ClearItems;
   cxtvMaster.DataController.Summary.FooterSummaryItems.Clear;
   for i := 0 to cxtvMaster.DataController.DataSet.FieldCount - 1 do
   begin
     cl  :=  cxtvMaster.CreateColumn;
     cl.DataBinding.FieldName :=
         cxtvMaster.DataController.DataSet.Fields[i].FieldName;
     if cxtvMaster.DataController.DataSet.Fields[i] is TNumericField then
     begin
       TNumericField(cxtvMaster.DataController.DataSet.Fields[i])
           .DisplayFormat  :=  ‘#,##0.00‘;
       cl.Width := 80;
       with TcxGridDBTableSummaryItem(
           cxtvMaster.DataController.Summary.FooterSummaryItems.Add) do
       begin
         Column  :=  cl;
         FieldName :=  cl.DataBinding.FieldName;
         Format  :=  ‘#,##0.00‘;
         Kind  :=  skSum;
       end;
     end
     else if cxtvMaster.DataController.DataSet.Fields[i] is TStringField then
       cl.Width := 100
     else
       cl.Width := 80;
     cl.HeaderAlignmentHorz :=  taCenter;
   end;  //if
 finally
   cxtvMaster.EndUpdate;
   Screen.Cursor := crDefault;
 end;
end;

posted on 2009-07-23 18:10  martian6125  阅读(188)  评论(0编辑  收藏  举报