clement Posted August 8, 2017 Share Posted August 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
Beginner Posted August 8, 2017 Share Posted August 8, 2017 Are you use calcfield? Quote Link to comment Share on other sites More sharing options...
clement Posted August 8, 2017 Author Share Posted August 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
davidizadar Posted August 15, 2017 Share Posted August 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.