Enumerating an Enum structure

A

Anthony Sox

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
 
C

Chris Dunaway

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
 
H

Herfried K. Wagner [MVP]

Anthony Sox said:
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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top