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

3

6

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?

Vortical answered 16/9, 2011 at 7:24 Comment(0)
C
3

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!

Callie answered 16/9, 2011 at 8:37 Comment(5)
Changing Configuration key as "SysDeletedObjects40" will work, but will this be the appropriate way to handle the problem ? am still not sure of a proper way to do itVortical
Only if you will hide B and D from the whole application (as stated in the answer). Otherwise you will have to create another enum, or do some programming (the two first options in the answer).Callie
yeah done that ... thanks for the answer, Even i think the same .. But is there any other way to do this than the 2 options you have specified ?Vortical
None I can think of. It is not possible to delete enum values or combobox values.Callie
Thanks Jan for the suggestions :)Vortical
M
4

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

Mccullough answered 23/8, 2018 at 18:3 Comment(0)
C
3

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!

Callie answered 16/9, 2011 at 8:37 Comment(5)
Changing Configuration key as "SysDeletedObjects40" will work, but will this be the appropriate way to handle the problem ? am still not sure of a proper way to do itVortical
Only if you will hide B and D from the whole application (as stated in the answer). Otherwise you will have to create another enum, or do some programming (the two first options in the answer).Callie
yeah done that ... thanks for the answer, Even i think the same .. But is there any other way to do this than the 2 options you have specified ?Vortical
None I can think of. It is not possible to delete enum values or combobox values.Callie
Thanks Jan for the suggestions :)Vortical
C
1

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)));
    }
}
Cristiecristin answered 25/10, 2011 at 22:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.