Monday, April 28, 2008

SysFormEnumComboBox - class allowing to show only some of the values for a comboBox

In Microsoft Dynamics AX 2009, a new class has been created, that got my attention recently after yet another question about this sort of thing was asked by a fellow Dynamics AX developer.

Often enough, we need to restrict the user selection from a particular ComboBox. Creating a new BaseEnum specifically for this purpose is a really cumbersome solution, which later might lead to problems of maintenance.

Originally, the SysFormEnumComboBox was designed to be used on forms to provide for this behavior. I modified the class slightly to allow for usage in RunBase Framework classes.
To demonstrate, how this class can be used, I modified the tutorial_RunBaseForm class and form, showing both scenarios: adding the control from the dialog method of the class, as well as adding it manually in the form design and methods.

To use this class, you need to know only one static method:

public static SysFormEnumComboBox newParameters(
FormRun _formRun,
int _comboBoxControlId,
enumId _enumId,
Set _allowedEnumValuesSet,
Form _form = null)

And here is an example of how you would use it:
sysFormEnumComboBox = SysFormEnumComboBox::newParameters(element, 
control::ComboBoxOnForm,
enumnum(InventTransType),
enumSet);

which means that the control ComboBoxOnForm will be bound to BaseEnum InventTransType, containing only values, found in the Set enumSet.

You can download the project for versions 4.0 and 2009 of Microsoft Dynamics AX through the following link:
download

P.S. It is also worth mentioning, that this class does not provide support for grids. It requires a stand-alone control, not bound to a database table field.

3 comments:

Anonymous said...

hi,

thanks for ideas.

But I try similar things on form CustTable and didn't work:(.
Field Blocked from table CustTable is enum CustVendorBlocked extend about new 2 elements.
I want show only original elements +1 new.
At init method I use your way(seup at general tabpage AutodataGroup administration -> no and autodeclaration to yes.

btw. Did I understand correctly that this way is used only enum interval? exapmle I have 0,1,2,3,4 elements and only 0,1,2 range not 0,1,4?

Thank you very much for ideas

Martin Mikes
martin.mikes@circon.cz

Vanya Kashperuk said...

What exactly did not work? Are you sure that you followed the guidelines correctly?
What AX version do you have?

The set of values you can use does not have to be sequential, so you can as well specify 0,1,4 as the range to display in the combo box.

If you export your xpo and send it to me, I might figure out what is wrong.
Or simply describe your problem in more details - what error message you get, or what behavior is incorrect?

Anonymous said...

I need to do that in a specific event. i.e. I have transaction main type and transaction subtype, when selecting a main type I want to filter the conbo to show specific fieds for each main type.
I tried it but it works only at the init event of the form.
thanks

Post a Comment

Please don't forget to leave your contact details if you expect a reply from me. Thank you