|
-
October 12th, 2006, 10:11 AM
#1
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.
-
October 12th, 2006, 12:45 PM
#2
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...
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
October 12th, 2006, 01:16 PM
#3
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?
-
October 12th, 2006, 01:52 PM
#4
Re: enum on database and in combobox
Code:
comboBox1.Items.AddRange(Enum.GetNames(typeof(YOUR_ENUM_TYPE)));
Should give you a route to try...
-
October 12th, 2006, 03:14 PM
#5
Re: enum on database and in combobox
Of course this doesn't solve the two-words problem.
I cannot bind this to the enum.
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
|