Jump to content

Recommended Posts

Posted

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.

 

Posted

Are you use calcfield?

 

No.

I write the below code in OnChange of the ColA & ColB (clientdataset).

ColC.Value := ColA.Value * ColB.Value;

 

The "ColC.Value" will not update in the grid.

Posted

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.

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...