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
}
}
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(); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With