?
Solved

Object binding a public enum property to a combobox

Posted on 2006-04-10
3
Medium Priority
?
741 Views
Last Modified: 2008-01-16
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
Comment
Question by:drabaecus
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
devsolns earned 750 total points
ID: 16416647
Take a look at this and see if this adds any benefit.  

http://msdn2.microsoft.com/en-us/library/y0wfd4yz.aspx
0
 

Author Comment

by:drabaecus
ID: 16422888
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
 
LVL 13

Expert Comment

by:devsolns
ID: 16423080
nice.  take care.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question