Search code examples
c#wpfenumspropertygrid

display int value from enum


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
        }
    }

Solution

  • 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(); }
    }