CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    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.

  2. #2
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

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

  3. #3
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    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?

  4. #4
    Join Date
    Aug 2006
    Posts
    16

    Re: enum on database and in combobox

    Code:
    comboBox1.Items.AddRange(Enum.GetNames(typeof(YOUR_ENUM_TYPE)));
    Should give you a route to try...

  5. #5
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    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
  •  





Click Here to Expand Forum to Full Width

Featured