给你写个小计吧, 你的dbgrid 不是通过数据源关联到数据集上了吗? var sqltext:string;with 数据集 do begin close;sql.clear;(纯属个人习惯) sql.add('select 字段1,字段2..字段n from table'); sqltext:=sql.text; sql.add('union select ''总计'',null 字段2....sum(字段n) from ('+sqltext); sql.add(') AS A'); open; end;
1 用dbgrid的ondrawdatacell事件 begin if (gdFocused in state) then begin if (field.fieldname=dbcombobox1.datafield) then begin dbcombobox1.left:=Rect.left+dbgrid1.left; dbcombobox1.top:=rect.top+dbgrid1.top; dbcombobox1.width:=rect.width+dbgrid1.width; dbcombobox1.visible:=true; end; end; end;
你的dbgrid 不是通过数据源关联到数据集上了吗?
var
sqltext:string;with 数据集 do
begin
close;sql.clear;(纯属个人习惯)
sql.add('select 字段1,字段2..字段n from table');
sqltext:=sql.text;
sql.add('union select ''总计'',null 字段2....sum(字段n) from ('+sqltext);
sql.add(') AS A');
open;
end;
用dbgrid的ondrawdatacell事件
begin
if (gdFocused in state) then
begin
if (field.fieldname=dbcombobox1.datafield) then
begin
dbcombobox1.left:=Rect.left+dbgrid1.left;
dbcombobox1.top:=rect.top+dbgrid1.top;
dbcombobox1.width:=rect.width+dbgrid1.width;
dbcombobox1.visible:=true;
end;
end;
end;