现想在STRINGGRID中实现如下的效果:
第一列 第二列 第三列 第四列 第五列 第六列
第二行 1 1 1 3
第三行 2 2 2 6第四行 3 3 3 9现想第六列中实现第行的加总,不知要在哪个事件中实现。加总要是实时的,比如单
元格中的数字变了,加总也变。自已写的代码总是不行,哪位能指正下procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
//c:integer;
//r:integer;
sum:integer;
vu:integer;
begin
with stringgrid1 do
begin
for arow:=1 to rowcount-1 do
begin
sum:=0;
for acol:=3 to colcount-1 do
begin
if cells[acol,arow]='' then
vu:=0
else
begin
vu:=strtoint(cells[acol,arow]);
end;
sum:=vu+sum;
if acol=colcount-1 then
begin
cells[colcount-1,arow]:=inttostr(sum);
sum:=0;
end;
end; end;
end;
end;
// end;
//end;
第一列 第二列 第三列 第四列 第五列 第六列
第二行 1 1 1 3
第三行 2 2 2 6第四行 3 3 3 9现想第六列中实现第行的加总,不知要在哪个事件中实现。加总要是实时的,比如单
元格中的数字变了,加总也变。自已写的代码总是不行,哪位能指正下procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
//c:integer;
//r:integer;
sum:integer;
vu:integer;
begin
with stringgrid1 do
begin
for arow:=1 to rowcount-1 do
begin
sum:=0;
for acol:=3 to colcount-1 do
begin
if cells[acol,arow]='' then
vu:=0
else
begin
vu:=strtoint(cells[acol,arow]);
end;
sum:=vu+sum;
if acol=colcount-1 then
begin
cells[colcount-1,arow]:=inttostr(sum);
sum:=0;
end;
end; end;
end;
end;
// end;
//end;
2.必须写触发事件,计算改变后的总值
procedure TForm1.Button1Click(Sender: TObject);
var
c,r,sum,vu:integer;
begin
r:=1;
c:=3;
sum:=0;
with stringgrid1 do
begin
for r:=1 to rowcount-1 do
begin
for c:=3 to colcount-1 do
begin
if cells[c,r]=''
then
vu:=0
else
vu:=strtoint(cells[c,r]);
sum:=sum+vu;
vu:=0;
//inc(c);
if c=colcount-1
then
begin
//sum:=sum+vu;
//vu:=0;
cells[colcount-1,r]:=inttostr(sum);
sum:=0;
break;
end;
end;
//r:=r+1;
end;
//r:=r+1;
end;
end;
我想要的是每行的加总和。