Bind a Combo or ListBox to an Enumeration
21-Jul-0909 Leave a comment
ComboBox1.DataSource = System.Enum.GetValues(GetType(PeopleNames))
Dim nameid As PeopleNames = CType(ComboBox1.SelectedValue, PeopleNames)
Note there should be no need to set the DisplayMember. If it does not work check that you have nothing on the control > DataBindings > Text binding
The variable “nameid” contains a 0, or 1, or 2 etc. depending on the value of the enumerated item that is currently selected.
May also bind to VS enumerations. Good use would be to bind to
ListBoxChartType.DataSource = System.Enum.GetValues(GetType(System.Windows.Forms.DataVisualization.Charting.SeriesChartType))