forum

Home / DeveloperSection / Forums / Get enum from enum attribute

Get enum from enum attribute

Anonymous User 2166 09-Dec-2013

public enum Als

{

    [StringValue("Beantwoord")] Beantwoord = 0,

    [StringValue("Niet beantwoord")] NietBeantwoord = 1,

    [StringValue("Geselecteerd")] Geselecteerd = 2,

    [StringValue("Niet geselecteerd")] NietGeselecteerd = 3,

}

public class StringValueAttribute : Attribute

{

    private string _value;

    public StringValueAttribute(string value)

    {

        _value = value;

    }

 

    public string Value

    {

        get { return _value; }

    }

}

And I would like to put the value from the item I selected of a combobox into a int:

int i = (int)(Als)Enum.Parse(typeof(Als), (string)cboAls.SelectedValue); //<- WRONG

Is this possible, and if so, how? (the StringValue matches the value selected from the combobox).


c# c# 
Updated on 09-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By