1

Possible Duplicate:
How do I enumerate an enum?

I am using the Microsoft Chart Controls for .NET 3.5 (C#) and have a chart in a winform.

My hope is to allow the user to change the color palette based on their preference.

How do I iterate through the color properties of the ChartColorPalette and add them to a combobox list?

I know it should be something like:

for each(something in ChartColorPalette)
{
  combobox.items.add(something.ToString);
}
Community
  • 1
  • 1
John M
  • 14,338
  • 29
  • 91
  • 143

2 Answers2

2

You can enumerate the names in your enum via the GetNames class method...

foreach(string s in Enum.GetNames(typeof(ChartColorPalette))
{
}

then later if you need the enum for the name you can parse the name value...

var val = (ChartColorPalette)Enum.Parse(typeof(ChartColorPalette),"theValue");
Tim Jarvis
  • 18,465
  • 9
  • 55
  • 92
2

See how to enumerate an enum.

Community
  • 1
  • 1
H H
  • 263,252
  • 30
  • 330
  • 514