Question Status

Verified
wjgoh asked a question on 18 Jul 2013 8:43 PM

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

AX newbie

Reply
Verified Answer
gl00mie responded on 19 Jul 2013 5:36 AM

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

Reply
Dominic Lee responded on 20 Jul 2013 5:56 AM

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.

kind regards,

Dominic Lee

My blog | PBC

This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Reply
wjgoh responded on 21 Jul 2013 11:53 PM

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?

AX newbie

Reply
gl00mie responded on 22 Jul 2013 2:50 AM

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).

Reply
wjgoh responded on 22 Jul 2013 6:52 PM

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?

AX newbie

Reply
Dominic Lee responded on 22 Jul 2013 6:55 PM

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

kind regards,

Dominic Lee

My blog | PBC

This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Reply
wjgoh responded on 22 Jul 2013 7:10 PM

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

AX newbie

Reply
gl00mie responded on 23 Jul 2013 12:38 AM

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?

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".

Reply
wjgoh responded on 23 Jul 2013 1:07 AM

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......

AX newbie

Reply
Verified Answer
gl00mie responded on 19 Jul 2013 5:36 AM

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

Reply