enum on database and in combobox
I have a class with an enum property.
I want to do two things:
1. Have a ComboBox on the form with the enum strings listed in the dropdown. I need to be able to format the enum string as I wish. For example:
Code:
enum
{
TwoWords,
Word
}
I want the combo box to show "Two Words" and "Word".
I need this for databinding - I am going to bind the combobox to the property of the type of that enum.
2. I want to store and retrieve the enum into a DataSet, and then copy the enum into the object property.
I hope that my questions are clear. I couldn't find any easy solutions to the problem.
Re: enum on database and in combobox
As far as my knowledge about C# goes, I don't think it would be possible... a key/value based collection can be used instead of an enum here? Or a wrapper class that takes the enum to construct its object and supply you with the string as needed... but I guess you must have thought of these alternatives.
//Nice blog by the way...:) :thumb:
Re: enum on database and in combobox
Thanks.
I can think of alternatives, but they are not so comfortable. I am trying to build, or at least design, a framework for others, and I want it to be as smooth as possible.
I want my class to have an Enum. I found some resources about using the Description attribute, and similar solutions, but none of these use binding.
Maybe I do need a wrapper of some sort. Any ideas?
Re: enum on database and in combobox
Code:
comboBox1.Items.AddRange(Enum.GetNames(typeof(YOUR_ENUM_TYPE)));
Should give you a route to try...
Re: enum on database and in combobox
Of course this doesn't solve the two-words problem.
I cannot bind this to the enum.