
Sometimes customers request a specific filter in a form. The filter is based on an enum and must have All element to display all records regardless of field value.
For example, a filter has 3 elements: All, Quotation, Order; although enum has only 2 elements: Quotation, Order.
To achieve the result you need to add a ComboBox
control in code
The algorithm is the following:
– an unbounded combobox control is added to a form
– All element and required base enum elements are added to the control during form initialisation
Code below shows how to do
public static void main(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
FormBuildComboBoxControl formComboBoxControl;
EnumId enumId = enumNum(ABC);
DictEnum dictEnum = new DictEnum(enumId);
int numOfValues = dictEnum.values() + 1;
int counter;
//Add dialog field of type ABC
dialogField = dialog.addField(enumStr(ABC));
formComboBoxControl = dialogField.control();
//Don't assign any enum type to Combobox
formComboBoxControl.enumType(0);
//Give the Combo box the same label of ABC enum
formComboBoxControl.label(dictEnum.label());
//Set the number of elements of the comboBOX (the elements of ABC plus one)
formComboBoxControl.items(numOfValues);
//Insert ABC elements inside the combobox
for(counter = 0; counter < numOfValues; counter ++)
{
formComboBoxControl.item(counter + 1);
formComboBoxControl.text(dictEnum.index2Label(counter));
}
//Add the "All values" element
formComboBoxControl.item(numOfValues);
formComboBoxControl.text('All values');
dialog.run();
}
The result will be this one
