473,322 Members | 1,241 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.

Enumerating an Enum structure

Does anyone know if its possible to use an enum structure as a data source
for a combo box or list box. if not, is it possible to enumerate an enum and
list it values

Thanks in advance

Nov 21 '05 #1
3 2742
Yes. You can. Check out the following:

http://msdn.microsoft.com/library/de...aluestopic.asp

The Enum.GetNames method returns all the names in the enum as an array of
strings, which you can databind to.

Scott Swigart - MVP
http://blog.swigartconsulting.com

"Anthony Sox" wrote:
Does anyone know if its possible to use an enum structure as a data source
for a combo box or list box. if not, is it possible to enumerate an enum and
list it values

Thanks in advance

Nov 21 '05 #2
I'm not sure about using an enum as a data source, but you can get its
values and names using the static methods Enum.GetNames and
Enum.GetValues

Nov 21 '05 #3
"Anthony Sox" <tr*******@hotmail.com> schrieb:
Does anyone know if its possible to use an enum structure as a data source
for a combo box or list box. if not, is it possible to enumerate an enum
and
list it values


\\\
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Load
Me.ListBox1.DataSource = _
[Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor = _
Color.FromKnownColor( _
DirectCast( _
[Enum].Parse( _
GetType(KnownColor), _
CStr(ListBox1.SelectedItem) _
), _
KnownColor _
) _
)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

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

Similar topics

4
by: Brian P. Bailey | last post by:
Hello, I'm trying to enumerate the fixed-pitch font families installed on a system. I am _not_ trying to create a generic monospaced font. I've tried looking at: FontFamily...
2
by: pdavis68 | last post by:
How can I iterate through all the values of an enum? I'm looking through all the information of the type in the watch window to see if there's some way to get at the values through reflection, but...
4
by: marc.gibian | last post by:
I have been trying to improve the quality of my C# and ADO.NET coding. One of the books I've read strongly advises against using string values to address individual values in DataRow objects. This...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
4
by: Shayne H | last post by:
What is the best way to enumerate a grouping of strings? The way I have been doing it is: Public Enum PlatformID Unknown Win16 Win32 Win32NT WinCE End Enum
3
by: Joe User | last post by:
Hi - I found the class below on another website (www.devx.com) and can't seem to figure out how to make a call to this class to retrieve the machines and put them in a listbox. I am definitely a...
4
by: | last post by:
Hi all, I currently have a custom vb object which has several Enum properties. Now, on the end-user web form I am manually displaying a drop-down list with the options for each of these properties....
10
by: Michael Feld | last post by:
Hello, does anyone know how to produce a data type which offers Enum-like IntelliSense in VS 2005? What I am trying to create is a type which is very similar to an enum, i.e. has a fixed set of...
1
by: Joe HM | last post by:
Hello - I have two Enums for which I would like to define type conversions ... Public Enum eA A2 = 0 A2 = 1 End Enum Public Enum eB B1 = 2
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...
0
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.