Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display int value from enum [duplicate]

I have a propertygrid which I need to create a combobox inside the propertygrid and display int value (1 to 9), I found using enum is the easiest way, but enum couldn't display int value, even I try to cast it to int, but I do not know how to return all the value. Any other way to do this? Thanks in Advance. Below is my code.

public class StepMode
    {
        private TotalSteps totalSteps;

        public TotalSteps totalsteps
        {
            get { return totalSteps; }
            set { value = totalSteps; }
        }
        public enum TotalSteps
        {
            First = 1,
            Second = 2,
            Three = 3,
            Four = 4,
            Five = 5,
            Six = 6,
            Seven = 7,
            Eight = 8,
            Nine = 9
        }
    }
like image 411
Mers Tho Avatar asked May 10 '16 02:05

Mers Tho


1 Answers

To get all values of the Enum try this

var allValues = Enum.GetValues(typeof(TotalSteps)).Cast<int>().ToArray();

and your totalSteps property should look like this

public int[] totalSteps
{
   get { return Enum.GetValues(typeof(TotalSteps)).Cast<int>().ToArray(); }
}
like image 86
Ramin Avatar answered Oct 01 '22 06:10

Ramin