procedure TfrmKcFzGl.Button1Click(Sender: TObject);
begin
inherited;
ADODataSet1.CommandText:='SELECT WZBM,WZMC,JLDW,RKSL,RKDJ,RKJE FROM 入库单';
ADODataSet1.Open;
DBGridEh1.DataSource.DataSet:=ADODataSet1;
//此时DBGridEh1将绑定并显示记录集ADODataSet1
请问接下来如何写代码,才能实现DBGridEh1有一个合计行,并能合计RKJE(入库金额)???
...
end;
11 个解决方案
#1
楼主是想增加一行吗?
#2
这个问题麻烦
我用dxdbgrid的时候自己有个Footer,很方便
如果你不嫌难看的话
就在dbgrideh下面放个label吧,用这个来显示
select sum(RKJE) from 入库单。
我用dxdbgrid的时候自己有个Footer,很方便
如果你不嫌难看的话
就在dbgrideh下面放个label吧,用这个来显示
select sum(RKJE) from 入库单。
#3
或者
var
s:integer;
with adoquery1 do
begin
s := 0;
sql.clear;
sql.add('select RKJE from 入库单');
open;
while not eof do
begin
s := s+strtoint(fieldbyname('RKJE').value);
next;
end;
label1.caption := inttostr(s);//显示RKJE的和
end;
var
s:integer;
with adoquery1 do
begin
s := 0;
sql.clear;
sql.add('select RKJE from 入库单');
open;
while not eof do
begin
s := s+strtoint(fieldbyname('RKJE').value);
next;
end;
label1.caption := inttostr(s);//显示RKJE的和
end;
#4
不仅麻烦,建议自己做控件
#5
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select dtvdate,cinvcode,je from songhuo1');
adoquery1.Open;
dbgrideh1.FooterRowCount:=1;
dbgrideh1.SumList.Active:=true;
for i:=0 to adoquery1.FieldCount-1 do
begin
dbgrideh1.Columns.Add;
dbgrideh1.Columns[i].FieldName:=adoquery1.Fields[i].FieldName;
if adoquery1.Fields[i].FieldName=edit1.Text then
begin
dbgrideh1.Columns[i].Footer.ValueType:=fvtsum;
dbgrideh1.Columns[i].Footer.FieldName:=edit1.Text;
end;
end;
end;
#6
以上你少加修改即可
#7
procedure TfrmKcFzGl.Button2Click(Sender: TObject);
var
// cCol: TDBGridColumnEh;
cFooterCol: TColumnFooterEh;
begin
inherited;
// cCol := TDBGridColumnEh.Create(vGrid.Columns);
//法一:
cFooterCol := DBGridEh2.Columns[12].Footers.Add; //RKSL
cFooterCol.ValueType := fvtSum;
//法二:
cFooterCol := DBGridEh2.FieldColumns['u_kcmd_cksl'].Footers.Add;
cFooterCol.ValueType := fvtSum;
//法三:
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
end;
var
// cCol: TDBGridColumnEh;
cFooterCol: TColumnFooterEh;
begin
inherited;
// cCol := TDBGridColumnEh.Create(vGrid.Columns);
//法一:
cFooterCol := DBGridEh2.Columns[12].Footers.Add; //RKSL
cFooterCol.ValueType := fvtSum;
//法二:
cFooterCol := DBGridEh2.FieldColumns['u_kcmd_cksl'].Footers.Add;
cFooterCol.ValueType := fvtSum;
//法三:
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
end;
#8
关注
#9
为何我不能给自己分配分数? 再问个问题就给分。
我在一个FORM中放了3个DBGridEh控件并绑定到3个记录集,如何写个通用过程,使单点任意一个DBGridEh的台头(列标题时)都能调用该通用过程进行数据集排序?如能解答我给70分
我在一个FORM中放了3个DBGridEh控件并绑定到3个记录集,如何写个通用过程,使单点任意一个DBGridEh的台头(列标题时)都能调用该通用过程进行数据集排序?如能解答我给70分
#10
我这有一个程序,第一次是升序,再击一次是降序,我用过了,好使
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;
#11
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
#1
楼主是想增加一行吗?
#2
这个问题麻烦
我用dxdbgrid的时候自己有个Footer,很方便
如果你不嫌难看的话
就在dbgrideh下面放个label吧,用这个来显示
select sum(RKJE) from 入库单。
我用dxdbgrid的时候自己有个Footer,很方便
如果你不嫌难看的话
就在dbgrideh下面放个label吧,用这个来显示
select sum(RKJE) from 入库单。
#3
或者
var
s:integer;
with adoquery1 do
begin
s := 0;
sql.clear;
sql.add('select RKJE from 入库单');
open;
while not eof do
begin
s := s+strtoint(fieldbyname('RKJE').value);
next;
end;
label1.caption := inttostr(s);//显示RKJE的和
end;
var
s:integer;
with adoquery1 do
begin
s := 0;
sql.clear;
sql.add('select RKJE from 入库单');
open;
while not eof do
begin
s := s+strtoint(fieldbyname('RKJE').value);
next;
end;
label1.caption := inttostr(s);//显示RKJE的和
end;
#4
不仅麻烦,建议自己做控件
#5
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select dtvdate,cinvcode,je from songhuo1');
adoquery1.Open;
dbgrideh1.FooterRowCount:=1;
dbgrideh1.SumList.Active:=true;
for i:=0 to adoquery1.FieldCount-1 do
begin
dbgrideh1.Columns.Add;
dbgrideh1.Columns[i].FieldName:=adoquery1.Fields[i].FieldName;
if adoquery1.Fields[i].FieldName=edit1.Text then
begin
dbgrideh1.Columns[i].Footer.ValueType:=fvtsum;
dbgrideh1.Columns[i].Footer.FieldName:=edit1.Text;
end;
end;
end;
#6
以上你少加修改即可
#7
procedure TfrmKcFzGl.Button2Click(Sender: TObject);
var
// cCol: TDBGridColumnEh;
cFooterCol: TColumnFooterEh;
begin
inherited;
// cCol := TDBGridColumnEh.Create(vGrid.Columns);
//法一:
cFooterCol := DBGridEh2.Columns[12].Footers.Add; //RKSL
cFooterCol.ValueType := fvtSum;
//法二:
cFooterCol := DBGridEh2.FieldColumns['u_kcmd_cksl'].Footers.Add;
cFooterCol.ValueType := fvtSum;
//法三:
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
end;
var
// cCol: TDBGridColumnEh;
cFooterCol: TColumnFooterEh;
begin
inherited;
// cCol := TDBGridColumnEh.Create(vGrid.Columns);
//法一:
cFooterCol := DBGridEh2.Columns[12].Footers.Add; //RKSL
cFooterCol.ValueType := fvtSum;
//法二:
cFooterCol := DBGridEh2.FieldColumns['u_kcmd_cksl'].Footers.Add;
cFooterCol.ValueType := fvtSum;
//法三:
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
end;
#8
关注
#9
为何我不能给自己分配分数? 再问个问题就给分。
我在一个FORM中放了3个DBGridEh控件并绑定到3个记录集,如何写个通用过程,使单点任意一个DBGridEh的台头(列标题时)都能调用该通用过程进行数据集排序?如能解答我给70分
我在一个FORM中放了3个DBGridEh控件并绑定到3个记录集,如何写个通用过程,使单点任意一个DBGridEh的台头(列标题时)都能调用该通用过程进行数据集排序?如能解答我给70分
#10
我这有一个程序,第一次是升序,再击一次是降序,我用过了,好使
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
temp, title: string;
begin
temp := Column.FieldName;
qusp.Close;
if Column.Index <> lastcolumn then
begin
if (Pos('↑', DBGrid1.Columns[LastColumn].Title.Caption) > 0) or (Pos('↓', DBGrid1.Columns[LastColumn].Title.Caption) > 0) then
DBGrid1.Columns[LastColumn].Title.Caption := Copy(DBGrid1.Columns[LastColumn].Title.Caption, 3, Length(DBGrid1.Columns[LastColumn].Title.Caption) - 2);
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[Column.Index].Title.Caption := '↑' + DBGrid1.Columns[Column.Index].Title.Caption;
lastcolumn := column.Index;
end
else
begin
LastColumn := Column.Index;
title := DBGrid1.Columns[LastColumn].Title.Caption;
if Pos('↑', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' desc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↓' + title;
end
else if Pos('↓', title) > 0 then
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
Delete(title, 1, 2);
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end
else
begin
qusp.Sql[icount] := 'order by ' + temp + ' asc';
DBGrid1.Columns[LastColumn].Title.Caption := '↑' + title;
end;
end;
qusp.Open;
end;
#11
DBGridEh3.FooterRowCount:=2; DBGridEh3.SumList.Active:=True;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[0].ValueType:=fvtSum;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers.Add;
DBGridEh3.FieldColumns['kcsw_cksl'].Footers[1].ValueType:=fvtAvg;