0

I have created a master-detail relation using ClientDataSets (Service & Addons). The Services are displayed in a DBLookupComboBox (cboServices) and once a service is selected the Addons are displayed in DBGrid (grdMain).

The Addons has a checkbox to indicate the Addon is selected, a name field, a quantities field that the user can change, a unit price field and a total price field.

I have created a OnQuantityChange method to update the total price using the unit price and quantity but how do I get the actual data from the row to do the updating? How do I reference the various fields in order to do something like the following:

grdMain.GetActiveRow.Column['TotalPrice'] := 
   grdMain.GetActiveRow.Column['UnitPrice'] * grdMain.GetActiveRow.Column['Quantity'];
Warren P
  • 65,725
  • 40
  • 181
  • 316
BrianKE
  • 4,035
  • 13
  • 65
  • 115
  • 2
    Isn't that a case for [Calculated Fields](http://docwiki.embarcadero.com/Libraries/en/Data.DB.TDataSet.OnCalcFields)? – Uwe Raabe Apr 23 '12 at 13:52
  • If so how would I set that up? – BrianKE Apr 23 '12 at 13:55
  • Thanks, I did find info on how to do this using a calculated field. – BrianKE Apr 23 '12 at 14:06
  • I'm not sure if Uwe could provide comprehensive information about "how to set calculated fields" in a single answer.. In any case, you'd like to refer to the fields of the dataset themselves to have their value, not by the active row of the grid. – Sertac Akyuz Apr 23 '12 at 14:07

1 Answers1

0

You can do that easily using calculated fields. I suggest you look at the following article for a detailed example with client dataset. Just search the article for calculated fields, you will find what you need.

TClientDataset example

GDF
  • 830
  • 5
  • 11