how to make button on delphi 7 to execute addition with all data in dbgrid delphi. for example i have database table with 3 coloumns show in dbgrid,
[CODE_NUMBER][ITEMS NAME][STOCK][NEW_STOCK]
001 Rackets 1 5
002 Sports Shoes 2 5
003 Golf Hat 3 5
... etc
How to create button when i click it, then dbgrid start addition
[STOCK] = [STOCK]+[NEW_STOCK]
after count in the first line, move to second line do the same addition and so on until the end of the record in dbgrid and delete data in [NEW_STOCK] coloumn. i've try with
if dbgrid1.fieldbyname('Code').value <> 0 then
begin
dbgrid1.fieldbyname('Stock').value := dbgrid1.fieldbyname('Stock').value + dbgrid1.fieldbyname('NEW_STOCK').value;
dbgrid1.next;
but only affect in the first line, nothing happen with the next lines in dbgrid
calculated field
. The calculated field is defined in the dataset and allows you to define the calculation in Delphi code. Look atOnCalcFields
in the help. – Hugh Jones