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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...