I want to use a combo box for entering a plain integer value.
In my application, some numerical values have special meanings, but any numerical value must be able to be entered (typed in).
The combo box must therefore show an edit field with a drop-down arrow to the right.
If the drop-down arrow is clicked, the drop-down must present a list of explanations (strings) for those special numerical values that have special meanings (for example "103 - Wait for next turn").
If the user clicks an entry from the drop-down list (instead of typing in the corresponding value directly), the corresponding numerical value must be transferred to the edit field.
I have tried the following:
- I set the ComboBox's
IsEditableproperty to true - I bind the
ItemsSourceproperty to a collection of objects which have both a numerical property (named"Value") and a string property (named"Explanation"). - I set the
DisplayMemberPathproperty to"Explanation"(the name of the string property above)
With that in place, I can freely type in any number I like, and the string explanation of each special number is properly displayed in the drop-down list. This is exactly what I want.
However, when I select one of the explanations from the drop-down list, it's the explanation string that gets transferred to the edit field, not the corresponding numerical value.
Question: How can I make the combo box transfer the numerical property ("Value") instead of the explanation text when I click an item from the drop-down list?