Jump to content

DBGrid - Calculattion


clement

Recommended Posts

Hi,

 

I use one uniDBGrid and clientdateset to allow user to enter value in ColA & ColB. The ColC is the result (ColA x ColB).

Formula: ColC = ColA * ColB

 

ColA  |  ColB  | ColC

1           1.5      1.5

2           3         6

2           2.5      5
 

The DBGrid cannot immediately show the result/value of ColC after the value of ColA & ColB is entered.

Can I know how to achieve it?

 

Thank You.

 

Link to comment
Share on other sites

Clement, you should use the event handler OnCalcFields. A TDataSet or descendant follows a sequence of events. The correct event for handling calculations (given the event sequence already in place) is OnCalcFields. You should implement something like this:

procedure TDM.tblItemsCalcFields(DataSet: TDataSet);
begin
  if not tblItemsQuantity.IsNull and not tblItemsPrice.IsNull then
    tblItemsTotal.Value := tblItemsQuantity.Value * tblItemsPrice.Value;
end;

In this snippet, I'm calculating the total value of Quantity items * Item Price.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...