问题
Suppose the combobox is linked to enum "ABC". The elements in it are A, B C and D.
Now I need to get only A and C in the combobox and not B and D?
Is this possible?
回答1:
It is not possible to delete enum values or combobox values.
You can duplicate the enum, then delete elements or change the order (but not the enum value). It will be your responsability to maintain both enum types synchronized with future changes.
To assign an enum to another incompatible enum, just add zero to it!
abc = myAbc + 0;
Or you can update your combobox using programming (using a combobox without specifying an enum type):
YourComboBox.add("A");
YourComboBox.add("C");
See also Enum as a Parameter in Dynamics AX about adding new values to a combobox.
While it is not possible do delete enum values at runtime, it is possible to hide enum values for the entire application. Just change the enum value's ConfiguratioKey to "SysDeletedObjects40", and it disappears as a legal value. I will assume that this configuration key is not enabled!
回答2:
Easy, create a run method in your form and put this:
public void run()
{
super();
YourCombo.delete(enum2str(YourEnum::B));
YourCombo.delete(enum2str(YourEnum::D));
}
Regards
回答3:
I'd use a combination of both! Do the combobox.add, but derive the values from the enum, and exclude the ones you don't want. This will let you iterate over an enum, and combine this with a little code and you should be set:
static void Job23(Args _args)
{
SysDictEnum sysDictEnum;
int i;
;
sysDictEnum = new SysDictEnum(EnumNum(SalesStatus));
for (i=0; i<sysDictEnum.values(); i++)
{
info(strfmt("%1", sysDictEnum.index2Label(i)));
}
}
来源:https://stackoverflow.com/questions/7441422/how-to-hide-enum-values-on-a-combo-box-at-runtime