5.4. How to create a calculated value field

Create a lineedit field with the name "calculated_field" and don't set any datasource or field property. Put the following code in the onpush action of a button. The value you want to display has first be formatted with format_number and then be set with hk_dsdatavisible.set_value.


Example 5-5. calculated values

   1 col1=hk_this.datasource().column_by_name("field_1")
   2 col2=hk_this.datasource().column_by_name("field_2")
   3 result=(col1.curval_asdouble()*col2.curval_asdouble())
   4 calcfield=cast_dslineedit(hk_thisform.get_visible("calculated_field"))
   5 calcfield.set_value(format_number(result,calcfield.use_numberseparator(),calcfield.precision()))