|
-
Sep 10th, 2003, 01:08 PM
#1
Thread Starter
Fanatic Member
Bind Enumeration to ComboBox
How can this be accomplished, setting the display and value members of the Combobox?
-
Sep 10th, 2003, 01:56 PM
#2
Can you explain more of what you are trying to do?
-
Sep 10th, 2003, 02:18 PM
#3
PowerPoster
Not through databinding, b/c an enum does not implement IList and the other interfaces necessary for databinding.
-
Sep 10th, 2003, 02:22 PM
#4
Thread Starter
Fanatic Member
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?
-
Sep 11th, 2003, 10:43 AM
#5
You can't bind directly but you can use the Parse and GetNames methods to link an Enum to a combo.
-
Sep 11th, 2003, 12:07 PM
#6
Thread Starter
Fanatic Member
Can you post sample code? Are you using cbo.Datasource and then Value/Display member or cbo.DataBindings...
-
Sep 11th, 2003, 12:30 PM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|