开发者

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

开发者 https://www.devze.com 2023-04-05 02:17 出处:网络
Suppose the co开发者_运维百科mbobox is linked to enum \"ABC\". The elements in it are A, B C and D.

Suppose the co开发者_运维百科mbobox 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?


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


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!


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)));
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号