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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Hide Enum of combobox during runtime.

(0) ShareShare
ReportReport
Posted on by

Hi all,

The case is I need a combobox showing element partially based on selection of another combobox.

I found a solution from google which manage the element by coding, by building combobox in init of form, so I can remove and insert element of combobox in another combobox.selectionChange.

But so far my understanding is to save a combobox value into datatable, the combobox need to be bound.

So how can I save the unbound combobox value? By setting the value into another non-visible control(bound) in form while selectionChange? Or maybe there is another easier way?

Thanks

WJGOH

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Denis Patrakov Profile Picture
    on at

    You can override modified() method of an unbound ComboBox and there set a form datasource's cursor field value based on the ComboBox selection.

  • dolee Profile Picture
    11,279 on at

    You can also consider using a bounded field for the enum, then:

    - create a table which contains one record per available enum value.

    - override the lookup() method to select from the new table, the available selections will be filtered base on your other enum field.

  • Community Member Profile Picture
    on at

    If element of Combobox B limited / filtered by selection of Combobox A, using the method both from above(so far i tested GL00MIE modified method)...

    Which mean the value of Combobox B must refer to Combobox A, in order to get the real meaning of value, is it?

    e.g:

    Combobox A Enum:

    0: Food

    1: Fruit

    Combobox B Enum(In Total):

    0: Rice

    1: Noodle

    2: Apple

    3: Orange

    After the filter, Combobox B Enum will become:

    Condition 1(If Combobox A Enum == 0)

    0: Food

    1: Fruit

    Condition 2(If Combobox B Enum == 1)

    0: Apple

    1: Orange

    This is what I seen now, am I correct?

  • Denis Patrakov Profile Picture
    on at

    That's right. Note that when you explicitly fill the list of Combobox' values you also have to explicitly convert the selection() value to your enum value (in the example above: 0 for Apple into 2 for Apple and 1 for Orange into 3 for Orange).

  • Community Member Profile Picture
    on at

    I'm not sure about the "explicitly convert the selection() value to your enum value", which method of combobox I should use for this action?

  • dolee Profile Picture
    11,279 on at

    Also in the modified field method I suppose, when you try to assign the unbound combobox value to the record.

  • Community Member Profile Picture
    on at

    Currently the only method I know to set Combobox value is Combobox.Selection(0).

  • Denis Patrakov Profile Picture
    on at

    [quote user="wjgoh"]I'm not sure about the "explicitly convert the selection() value to your enum value", which method of combobox I should use for this action?[/quote]Here's the problem: when you use a enum to provide ComboBox values, the form control uses enum value labels to display selection options and uses enum numeric values to return the user selection. That is, if you have a enum TransType with values 0 "Ledger", 5 "Cust", 10 "Vend", 127 "Bank" and use this enum for a ComboBox then you can expect ComboBox.selection() to return only values 0, 5, 10, or 127 - and you can directly assign ComboBox.selection() to a enum field. But in case you explicitly populate a ComboBox with a subset of a enum value labels (say, "Cust" and "Vend"), the ComboBox.selection() will return a zero-based ordinal number of a selected value (0 for "Cust" and 1 for "Vend") which doesn't match your enum values (0 is "Ledger" instead of "Cust" and 1 is an invalid value for the enum). So when you populate a ComboBox with your custom values you should save somewhere the mapping (0→5 for "Cust" and 1→10 for "Vend"), and after you get the ordinal value from the ComboBox.selection() you have to use that mapping to get a enum numeric value from the selection ordinal value. That is if selection() returns 1 you should map it to value 10 which is a valid enum value for "Vend".

  • Community Member Profile Picture
    on at

    Thanks for your help, I found and figure out this just now, so I verified the answer.

    Recently I got error on reply in this community.....Sometimes I gave up to reply......

  • Ajay Kumar Y Profile Picture
    218 on at

    Hi,

    I have a similar requirement as yours, but with a little change in it as below.

    I have a combox (in a grid) on a form bounded to an enum with say 10 values in it. Now I want to hide element 6,8 and 9.

    The only solution I found for bounded combobox was to delete the element, but than the selection is messed up because if you select the 10 element of the enum you get the wrong value (value 6)

    How can I fix this?

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

News and Announcements

Season of Giving Solutions is Here!

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

#2
TAHER Mehdi Profile Picture

TAHER Mehdi 3

#3
Nakul Profile Picture

Nakul 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans