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?

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
Tejashree S
  • 311
  • 1
  • 12
  • 27

3 Answers3

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

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!

Community
  • 1
  • 1
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • 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 it – Tejashree S Sep 19 '11 at 12:02
  • 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). – Jan B. Kjeldsen Sep 19 '11 at 12:40
  • 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 ? – Tejashree S Sep 19 '11 at 12:53
  • None I can think of. It is not possible to delete enum values or combobox values. – Jan B. Kjeldsen Sep 19 '11 at 13:01
  • Thanks Jan for the suggestions :) – Tejashree S Sep 19 '11 at 16:31
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)));
    }
}
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71