FormComboBoxControl

FormComboBoxControl

Work with ComboBoxes in a form with X++.
Example: Use the selected value. This example shows how to find the selected value of a ComboBox and use that value in X++ code.

To work with a control in X++, the AutoDeclaration must be set to YES. In the control, choose properties and set AutoDeclaration to YES.



Find the methods for a ComboBox in the form (Form, Designs, Design, ... Group, ComboBox(name), Methods). Right click Methods, Override Method, choose "SelectionChange".



We added a YesNo to addresses to indicate a PO box. This code disables the PO Box checkbox for some values of the AddressType combo box. public int selectionChange {   int ret; ;

ret = super;

// Do not allow PO boxes for DELIVERY or SERVICE if ((IdentificationGroup_type.selection == AddressType::Delivery) ||        (IdentificationGroup_type.selection == AddressType::Service)) {       AddressGroup_jsIsPOBox.enabled(false); }   else {       AddressGroup_jsIsPOBox.enabled(true); }

return ret; }

Example: Add ComboBox items with X++. This example uses a ComboBox dropped on a form. Set AutoDeclare = YES on the new combo box on the form. In the Form's init method, use the following code to add items to the ComboBox, use the count of items, and change the combo box type. public void init {   ;    super;

CodeComboBox.add("Thingy One"); CodeComboBox.add("Thingy Two"); CodeComboBox.add("Thingy Three"); //CodeComboBox.add("Thingy Four");

info(int2Str(CodeComboBox.items)); if (CodeComboBox.items < 4) {       CodeComboBox.comboType(1); }   else {       CodeComboBox.comboType(0); } }

In my form the comboType does not change the appearance of the combo box. The appearance also does not change if I use the properties of the combo box and set ComboType to "Standard" or "List". (If anybody has different results, please edit this page.)