By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Enumerating an Enum structure

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.