Wednesday, January 8, 2014

Hide selected enum values in form control using X++ code

Removing some of the elements that are not needed when they are shown in a combo-box on a form.To achieve this behavior Microsoft has given a class just for that purpose. The class is “SysFormEnumComboBox”.

Here is a sample code snippet that depicts how to use this class on a form having a combo-box control: 

Simply override the init() of the form and add the code.

public void init()
{
    SysFormEnumComboBox     sysFormEnumComboBox;
    Set enumSet = new Set(Types::Enum); // collection of selected values.
 
    enumSet.add(HMDaysName::Monday);
    enumSet.add(HMDaysName::Wednesday);
    enumSet.add(HMDaysName::Friday);
    

  SysFormEnumComboBox = SysFormEnumComboBox::newParameters(element,                                                 element.controlId(formControlStr(TestForm, ComboBoxCtrl)),  enumName2Id(enumStr(HMDaysName)), enumSet,"Select");
    

    super();
    SysFormEnumComboBox.select(HMDaysName::Friday); // To select value in combo
}

No comments:

Post a Comment