I was playing around with enum for a little while. I end up using Alex
Kolesnichenko, 2005 HumanReadable Attribute.cs form chap project
one caveat when you set the combobox box to his arraylist of
HumanReadablePair
you should also set
the displayMember to "HumanReadableName"
for example
in form_load
I have
ResourceManager resources =
new ResourceManager("RegexParse.Strings",
Assembly.GetExecutingAssembly()); // "RegexParse" is my namespace for the
project
// Get human-readable enum values
ArrayList regexCategories =
EnumToHumanReadableConverter.Convert(typeof(regexC ategory), resources);
// note regexCategory is a **public** enum type iwthin the
class
// Bind controls to data
comboBoxRegexCategory.DataSource = (ICollection)regexCategories;
comboBoxRegexCategory.DisplayMember = "HumanReadableName";
comboBoxRegexCategory.SelectedItem = regexCategory.eSimple;
I don't pretend to understand why I need public scope for the enum to work
but it worked for me
I don't need coding classes per enum combo but I do have to either use
attributs on enum or enter the relevant info in Strings.resx
good luck
ref: Humanizing the Enumerations - The Code Project - C# Programming
you could even compile the HumanReadableAttribute.cs into a dll and shared
among your projects if you wish
"Cralis" <ad***@myschoolmates.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
I have a List of data objects.
I need to populate a ComboBox with the 'Description' field from the
objects.
I can do that with cmbBx.Items.Add( myObject.Description.ToString() );
myObject has 2 fields for example. id and description.
Later, I need to get the id of the selected item in the ComboBox...
In Delphi, I'd create a StringList, and add the ID to that, and then
just match up the index of the combobox with the corrasponding index
of the StringList to objtain the selected descriptions ID.
Is there a better way to do this in C#?