Possible Duplicate:
Cast string to enum with enum attribute
I have a enum
like this:
public enum IddFilterCompareToCurrent
{
[StringValue("Ignore")]
Ignore,
[StringValue("Pre-Post")]
PrePost,
[StringValue("Custom")]
Custom
}
I also have some DomainUpDown
controls that are filled with same values of that enum I defined, exept that because enum does not accept -
character, I had to use Attributes
to match them with DomainUpDown
contents.
Now my question is how can I insert the selected item of a domainupdown into a variable of that enum type?
something like:
private IddFilterCompareToCurrent myEnum = Enum.Parse(typeof(IddFilterCompareToCurrent), domainUpDown1.SelectedItem.ToString());
I get this error:
Cannot implicitly convert type 'object' to 'Filtering.IddFilterCompareToCurrent'. An explicit conversion exists (are you missing a cast?)