473,387 Members | 1,504 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,387 software developers and data experts.

Enum to ListBox

Is there a way to add a list of items from an enum to a ListBox, and
be able to reference them by their 'id'?

I have this:

public enum Chemistry
{
Lipo = 1,
NiMH = 2,
NiCl = 3,
Pb = 4
}

So is there anyway to do something LIKE:

foreach (item i in Chemistry)
{
ListBox.Items.add ( i );
}
Jan 6 '08 #1
2 9617
Found a 'sort of' example. Trying this, but it's breaking. However, I
think it's on the right track...

foreach (string myType in
Common.Globals.Chemistry.GetNames(typeof(string)))
cmbChemistry.Items.Add(myType);
Jan 6 '08 #2
Sorted!!
Sorry, the answer, for those who may want to know, is:
foreach (string myType in
Enum.GetNames(typeof(Common.Globals.Chemistry)))
cmbChemistry.Items.Add(myType);
Jan 6 '08 #3

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

Similar topics

6
by: Laszlo Szijarto | last post by:
What's the best way to recurse through the members of an enum? I want to take an enum and dump into a ListBox the enum's names. Thank you, Laszlo
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
2
by: Lance | last post by:
Can somebody tell me how to allow the user to check and uncheck Enum flags in a PropertyGrid. In other words, how to display a drop down box that contains a check next to each enum value as well as...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
0
by: Petr SIMUNEK | last post by:
Hi all... In a WebService I have Public Enum declaration as follows: ---------- Public Enum ImgCat Cat Model Manufacturer Source Payment
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.