Bind a Combo or ListBox to an Enumeration

While this works, most Enum are in Camel case and do not have spaces, which may not be what you want

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))

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: