5,392
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, StdCtrls,ADODB,DB;
type
TForm1 = class(TForm)
Button1: TButton;
dxDBGrid1: TdxDBGrid;
dxDBGrid1Column1: TdxDBGridColumn;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FGrid:TdxDBGrid;
FQuuery:TADOQuery;
FDataSource:TDataSource;
procedure CreateControl;
procedure CreateGrid;
procedure CreateCol(colCaption,colName,colField:string;colWidth:Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.CreateGrid; //创建dxDBGrid
begin
FGrid := TdxDBGrid.Create(Self);
FGrid.Parent := Self;
FGrid.Width := Self.Width;
FGrid.Height := 500;
FGrid.OptionsDB ;= FGrid.OptionsDB + [edgoLoadAllRecords]; //用于列汇总
FGrid.ShowSummaryFooter := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateGrid;
end;
procedure TForm1.CreateControl;
begin
FQuuery := TADOQuery.Create(nil);
//FQuuery.Connection := 你的链接
FDataSource := TDataSource.Create(nil);
FDataSource.DataSet := FQuuery;
CreateGrid;
FGrid.DataSource := FDataSource;
end;
//读取相关信息,循环调用此方法创建列
procedure TForm1.CreateCol(colCaption,colName,colField:string; colWidth: Integer);
var
col : TdxDBTreeListColumn;
begin
col := FGrid.CreateColumn(TdxDBTreeListColumn);
col.Caption := colCaption;
col.Name := colName;
col.FieldName := colField;
col.Width := colWidth;
//如果此列需要汇总
col.SummaryFooterField := colField;
col.SummaryFooterFormat := '合计:0.00';
end;
end.