Enumerating an Enum structure

  • Thread starter Thread starter Anthony Sox
  • Start date Start date
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
 
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
 
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
///
 
Back
Top