Search code examples
formscheckboxaxaptax++dynamics-ax-2012

How to set a CheckBox value from code?


I have a checkBox, enum type NoYes. I want to set a value to CheckBox control in my Form equal to a Table field value, using X++ code.

For example, I want have the same value for CheckBox equal to value Enum field TableA.FieldEnum.

How I have to do?

Thanks for your time!

Enjoy!


Solution

  • Use datasource and dataField methods on the control:

    mycheckBox.datasource("TableA"); //Data source name
    mycheckBox.dataField(fieldNum(TableA, FieldEnum));
    

    Don't forget to set AutoDeclaration of the myCheckBox control to Yes.