Following the approach from the VC excample, I would recommend to go for a drop down list (non-editable verison of the combo box). You can then
- Simply fill it with the values of the
SearchMode
enum(!). Then in theSelectionChanged
even you could just convert these strings back to the actual enum values by means of theSystem.Enum.Parse
method and set it on theSearchMode
property. - If you are after a more operator-friendly text, then build two
System.Dictionary<string, string>
s that map the enum values to what you want to display to the user and vice versa. Use these dictionaries to fill the box and (in theSelectionChanged
even) to convert back to the enum. - Of course you could also use the
SelectedIndex
of the combo box and just cast this to an integer. As long as you add the strings strictly in the order in which they appear in the enum this is safe.
The twist with the conversion of int
to enum
would also work with a set of radio buttons. If you only want a non-contiguous set of the enum values (e. g. SEARCHMODE_THRESHOLD
which maps to 0 and SEARCHMODE_CONTRAST
which maps to 2) you could, for example, use two radio buttons only and store the associated enum value in the Tag
member of the radio button and apply it in the changed event of the radio button.
Which method you use is to a great extent a matter of taste I guess.