Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking with sum

Status
Not open for further replies.

filipe26

Programmer
Mar 17, 2003
152
0
0
PT
Hi i have a Tstringgrid with a currency fields and a Tlabel.What i want to do is when i change one currency field of the stringgrid calculates imediatly the label with the sum of all fields.Thanks
 
OnSetEditText is one event you could use:

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var i : integer; Sum:single;
begin
Sum:=0;
for i := 1 to StringGrid1.RowCount do
try
if StringGrid1.Cells[ACol,i] <> '' then
Sum:= Sum + StrToFloat( StringGrid1.Cells[ACol,i]);
except
// ignore any errors in conversion
end;
Label1.Caption := FloatToStr(Sum);
end;


That works in D7, there should be similar things in other versions of Delphi.
 
But i dont have the event editor OnSetEditText and i use delphi7.
 
hi

I have OnSetEditText. Which Delphi 7 have you got? I've got Professional.

lou

 
Sorry it's not a tstringgrid but a dbgrid.thanks anyway
 
But my problem is the same.I have in a table one field with for example 3 records of currency type and by other side a dbtext.What i want is when i change a value of the records will change too the sum into dbtext.Thanks.
 
Is there any reason why you can't use a TQuery to sum up the necessary fields in the underlying table ?

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top