Dll中使用cxGrid时,需初始化与释放
uses
dxCore;
initialization
dxInitialize;
finalization
dxFinalize;
关联数据源
TcxGrid--->TcxGridLevel--->TcxGridDBTableView
TClientDataSet
TDataSource
TcxGridDBTableView的DataController(DataSource)关联对应的TDataSource,TDataSource的DataSet关联对应的TClientDataSet,查询对应的数据集到TClientDataSet。
主从表关联
设置主表的
KeyFieldNames=id
detailKeyFieldName=id
设置从表的
KeyFieldNames=id
masterKeyFieldName=id
注:主表与从表都要有字段id
存在主从表时展开与收缩主表
cxgrdView1.ViewData.Expand(True); //展开。cxgrdView1是TcxGridDBTableView的名字
cxgrdView1.ViewData.Expand(True); //收缩
导出Excel
procedure DoOnExport;
begin
if not Assigned(cxgrd1) then
begin
ShowInfoMsg('列表对象不存在...');
Exit;
end;
with SaveDialog1 do
begin
Filter := '*.xls|*.xls';
if Execute then
ExportGridToExcel(SaveDialog1.FileName, cxgrd1, False, true, true, 'xls');//第三个参数
//是指导出excel时是否展开父级下的子表导出
end;
end;