web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Problem With Enum Value Assignment

(0) ShareShare
ReportReport
Posted on by

Hi there,

  I have an enum called Position containing the following values:

i) First

ii) Second

iii) Third

  I have a combobox which is based on this enum.  However, in the enter event of the combobox, I deleted the first entry using this code:

public void enter()
{
super();
this.delete(enum2str(Position::First));
}

  Now, I am using this code to get the selected enum value from the combobox:

Position    position;

;

position = Combobox.selection();

  The problem is that, when I select Second as the value in the combobox, the value assigned to the position variable is First.  I think that this is due to the fact that the deletion of the first enum value in the Combobox resulted in label Second having a value 0 and label Third having a value 1.  However, when assigned to the variable position, the label Second with value 0 is translated to First.

  How can I solve this please?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    The problem is you are returning combobox value.

    To solve it you have to do a switch or if.

    something like ..

    switch (Combobox.value())

    {

        case 1:

              position = Position::second;

               break;

        .....

    }

  • Community Member Profile Picture
    on at

    Where I said Combobox.value is combobox.selection ^^

  • Community Member Profile Picture
    on at

    Hi Xavier.  Thank you for your answer.  The problem is that the enum values may change in the future :s

  • Community Member Profile Picture
    on at

    well, may you could compare with the text

    switch (combobox.valueStr())

    {

      case enum2str(Position::Second)):

      ....

    }

  • Community Member Profile Picture
    on at

    Hi Anthony,

    I think you are making things dificult for yourself by deleting the values in the combobox?

     

    Instead of using the enum and deleting the values that you do not need, simply build the comboBox values that you do need in the run method of your form, using the _control.add() method?

     

    Hope this helps ;)

  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi Anthony.

    I agree with dynamic_jay. This seems like a very difficult way around, I also don't think I've personally ever seen standard AX remove items from a combo box like you are doing. I know in .NET it is fairly common but not AX.

    Could you maybe explain your functional requirement, there may be a much easier way to do what you want.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans