How to create a calculated value field
Prev | Chapter 5. Tips and tricks | Next

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

    col1=hk_this.datasource().column_by_name("field_1")
    col2=hk_this.datasource().column_by_name("field_2")
    result=(col1.curval_asdouble()*col2.curval_asdouble())
    calcfield=hk_thisform.get_pyvisible("calculated_field")
    calcfield.set_value(format_number(result,
    calcfield.use_numberseparator(),calcfield.precision()))

Prev | Up | Next
How to create a table | Home | How to use the last inserted value as a default for the next row that will be inserted