• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

Object binding a public enum property to a combobox

I'm trying to use object binding in a vs2005 c# app - which works fine in general. However, i have a situation where one of the public properties of a class is an enum, which i would like to use a combobox to display the available options. Unfortunately, the bound winforms control only displays the default (first entry) in the enum and none of the others.

Is there a way to have the combobox display all options - similar to the following: combobox.datasource = Enum.GetNames(typeof(PersonStatus)); -  with an existing object setting the list index to the correct value for that instance?

Class and enum definitions as follows:

public enum PersonStatus
{
     Active = 0,
     Inactive = 1,
     Deceased = 2
}

public class Person
{
     private string m_Firstname;
     private string m_Surname;
     private PersonStatus m_Status;

     public Person()
     {
     }

     public Firstname
     {
          get { return m_Firstname; }
          set { m_Firstname = value; }
     }

     public Surname
     {
          get { return m_Surname; }
          set { m_Surname = value; }
     }

     public Status
     {
          get { return m_Status; }
          set { m_Status = value; }
     }    
}


Any insight would be greatly appreciated.
0
drabaecus
Asked:
drabaecus
  • 2
1 Solution
 
devsolnsCommented:
Take a look at this and see if this adds any benefit.  

http://msdn2.microsoft.com/en-us/library/y0wfd4yz.aspx
0
 
drabaecusAuthor Commented:
Well, that wasn't exactly what i was after but it lead me to combine what the wizard provides with the manual setting of the datasource which appears to have done the trick.

i.e. i used the wizard to create object binding to winforms controls, using a combo box for the enum property then in the form constuctor set the datasource of the combo box using: combobox.datasource = Enum.GetNames(typeof(PersonStatus));

0
 
devsolnsCommented:
nice.  take care.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now