473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Iterating through an enumeration?

Is it possible to iterate through all of the possible values of an enumeration? (with foreach, maybe?)

What I need to do is fill a ComboBox with all possible values for an enumeration.
e.g

foreach ([value] in [enumeration])
{
comboBox1.Items.Add (value.ToString ("G");
}

Is this possible? Is so, how?

Thanks in advance.

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>O4wv1h3hl0mLCsTMhEIFKQ==</Id>
Nov 16 '05 #1
1 8804
Jamie,

You can iterate through the enum by looking at its value. I have provided a
sample below.

I hope this helps.

------------------

enum Color{Red,Blue,Green,Yellow};
.................
Type colors = typeof(Color);
foreach(string s in Enum.GetNames(colors))
comboBox1.Items.Add(s);

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
8
by: Imran | last post by:
Hello All I have a enum decla like this enum Days // Declare enum type Days { saturday, // saturday = 0 by default sunday = 0, // sunday = 0 as well monday, ...
34
by: Christopher Benson-Manica | last post by:
If an array is sparse, say something like var foo=; foo=4; foo='baz'; foo='moo'; is there a way to iterate through the entire array? --
1
by: Jamie Winder via .NET 247 | last post by:
Is it possible to iterate through all of the possible values of an enumeration? (with foreach, maybe?) What I need to do is fill a ComboBox with all possible values for an enumeration. e.g ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
10
by: Ken Foster | last post by:
I have a hashtable keyed by some name, holding an instance of an object. Most of the time I use the hashtable in the traditional sense, given a name, I lookup the object, then I run a method on...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
3
by: Daniel | last post by:
Hey guys i have a array of daya that i wish to iterate through. the only catch is i need to start from a certain position but on reaching the end of the array go back to the start and do the...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
9
by: Ben Rudiak-Gould | last post by:
Background: I have some structs containing std::strings and std::vectors of other structs containing std::strings and std::vectors of .... I'd like to make a std::vector of these. Unfortunately the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.