How to hide enum values on a combo box at runtime?

偶尔善良 提交于 2020-01-04 03:14:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!