How can this be accomplished, setting the display and value members of the Combobox?
Printable View
How can this be accomplished, setting the display and value members of the Combobox?
Can you explain more of what you are trying to do?
Not through databinding, b/c an enum does not implement IList and the other interfaces necessary for databinding.
But to create a bindable name value collection that implements IBindingList you have to implement a whole shlew of functions and properties that I don't need. Is there any other way?
You can't bind directly but you can use the Parse and GetNames methods to link an Enum to a combo.
Can you post sample code? Are you using cbo.Datasource and then Value/Display member or cbo.DataBindings...
I'm not really 'binding' except to the array of enum names. To get the value you can just parse the text though.
VB Code:
Public Enum Testers Test1 Test2 Test3 End Enum Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'fill combo with names of enum ComboBox1.DataSource = [Enum].GetNames(GetType(Testers)) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'convert the combo text back to an enum MessageBox.Show([Enum].Parse(GetType(Testers), ComboBox1.Text)) End Sub