binding to business object with property datatypes as enum

binding to business object with property datatypes as enum

Old forum URL: forums.lhotka.net/forums/t/3176.aspx


rd_bigdog posted on Wednesday, July 11, 2007


I have a business object I want to use for binding. There are a series of combobox on the form that are populated via a bindingsource which sets the DataSource, DataMember, ValueMemeber. THis populates the combo with available values. Now, I bind all the controls on teh form to my business object. The BO has a property which I set to be bound to the SelectedValue of the combo. The property in question is defined as an enum. It seems like the binding mechanism cannot read/write from the property when defined as an enum. If I change it to Integer, it all works correctly.

Does anyone know the cause of this issue? Is there a work around or something I need to do to make this work? If I has to use integers for my properites, it will not be pretty, I have dozens of enums and the code will get very ugly fast.

Thanks in advance for any assistance you may provide.

hurcane replied on Wednesday, July 11, 2007

Enums *are* integers. The enum values are only around in your source code. When it is compiled, they all become integers. Suppose you have an enum with members Red, White, and Blue. Red = 0, White = 1, and Blue = 2.

You probably want your enum options to display with a user-friendly value in the combo box (like Red, White, or Blue). I think you're going to need an additional object that represents the list of those values. I haven't tried this, but perhaps you could use reflection against the Enum to generate the list? I'm not sure if reflection will let you retrieve "Red" out of the enum type, but it could be worth exploring.

rd_bigdog replied on Thursday, July 12, 2007

Hi,

Thanks for your reply.

So, what is happening is that I am not binding the combobox to the enum values. I am binding the combo box to a List object that contains the values loaded from the database. However, to represent the values loaded in the database, I use enums in the application.

So, for example I have,

Public Enum MyEnum

Red

White

Blue

End Enum

 

And in my business object, I have a property

public property SomeColor as MyEnum

Get...

Set...

End property.

 

I have a binding source that is set to an Object of a ReadOnlyList  that is used to populate the combobox. Then, in my business object for the overall form, I have a property like above. I bind teh SelectedValue to the property in the Business Object so that when an object is being edited, the combobox shows the right value.

I put a breakpoint on teh Get and Set routine in teh property. When I change the value in the combobox, the set never gets called, but the Get is getting called 2 or 3 times. Then the form goes into a state where I cannot even take teh focus of the combobox in question, can't even close the form with the controlbox.

I am going to do some isolated testing today, but there seems to be a limitation here...hoping I am wrong though.

 

Rick.

david.wendelken replied on Thursday, July 12, 2007

I'm a bit confused.

Enums are a static construct, and building a list of values from the database is, by definition, a dynamic thing to do.  So I'm concerned about keeping the list of values in the enum the same as the list of items in the database.  It just feels like a design mismatch to me.

Why not load an NVList (from NameValueListBase) from the database and bind it to the combobox?  That's what it's for! :)

rd_bigdog replied on Thursday, July 12, 2007

Hello,

Ok, so binding a list of items to the combobox is not the issue.

Yes, we have enums that are kept in sync with values from the database, good or bad, that is how it was done.

I bind the combobox based on an id that will give me a group of related possible values for a particular domain from the database (also b/c we are supporting multiple languages, this is in teh database). This is fine.

My issue is with the business object that has attributes of those enum types.

The business object has a property, for example, a car object, with a color property, wher the only options are red,white,blue as the enum above. So, when declaring the property on the Car object, it is delcared as the enum type. Why? So that when developers are coding against the property, they immediatly see the options for the enum...this is very common practice throughout the entire .Net framework.

So, I have a winform to manage my 'car' object. I use a combobox to give the user the limited choices they have on colors. I load the available values from the database in teh appropriate language for the user. I bind all the controls on my winform to by Car object. The combobox selected value is bound to the color property whose datatype is defined as the colors enum above.

The winform is not behaving nicely in this situation. It is not calling the Set on teh property when the value is changed. It is calling the get,but not changing the value in the combobox based on teh value of the property when the property datatype is the enum.

Please note that my issue has nothing to do with loading the combobox, it has to do with binding the comboboxes on the form to properties of my business object.

rd_bigdog replied on Thursday, July 12, 2007

I know this is down the path of a general .Net thing now, but I am trying to do a proof of concept with the CSLA framework with our existing application. And this is how I came accross this. Here is a sample app I whipped up that will demonstrate the problem.

Public Enum MyEnum

One = 1

Two

Three

Four

End Enum

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim sortedList As Collections.ArrayList = New ArrayList

sortedList.Add(New myItems(-1, ""))

sortedList.Add(New myItems(1, "One"))

sortedList.Add(New myItems(2, "Two"))

sortedList.Add(New myItems(3, "Three"))

sortedList.Add(New myItems(4, "Four"))

ComboBox1.DataSource = sortedList

ComboBox1.DisplayMember = "Value"

ComboBox1.ValueMember = "Key"

Dim _bo As MyBO = New MyBO()

MyBOBindingSource.DataSource = _bo

End Sub

Public Class myItems

Private Dim _key As Integer

Private Dim _value As String

Public Property Key() As Integer

Get

Return _key

End Get

Set(ByVal value As Integer)

_key = value

End Set

End Property

Public Property Value() As String

Get

Return _value

End Get

Set(ByVal value As String)

_value = value

End Set

End Property

Public Sub New(ByVal key As Integer, ByVal value As String)

_key = key

_value = value

End Sub

End Class

End Class

 

Public Class MyBO

Public Property X() As EnumClassLibrary.MyEnum

Get

Return _x

End Get

Set(ByVal value As EnumClassLibrary.MyEnum)

_x = value

End Set

End Property

Private _x As EnumClassLibrary.MyEnum

Public Sub New()

X = EnumClassLibrary.MyEnum.Four

End Sub

smiley riley replied on Thursday, May 15, 2008

david.wendelken:

I'm a bit confused.

Enums are a static construct, and building a list of values from the database is, by definition, a dynamic thing to do.  So I'm concerned about keeping the list of values in the enum the same as the list of items in the database.  It just feels like a design mismatch to me.

Why not load an NVList (from NameValueListBase) from the database and bind it to the combobox?  That's what it's for! :)

Enums are a great idea for static data (Closed sets of choices) that other tables/objects feed off. Drives me mad when I see applications with magic numbers.

GetAllOrdersByType(1);

What does it mean???

Much better to use

GetAllOrdersByType(OrderType.CeaseOrder);

ajj3085 replied on Thursday, July 12, 2007

That's not quite true; enums are first class members.  by default, using an enum will have the actual enum name display in the combobox, if you were to databind them.  In other words, Red, White and Blue woudl be displayed, not 0, 1, or 2.

Also, not all enums are ints; you CAN create enums which inherit from short or long, as you need, although I think that's discouraged.

dshafer replied on Thursday, July 12, 2007

Rick,

I have a similar setup to yours where I have a "lookup" table in the database with values to populate combo boxes.  I also have corresponding enums with these "lookup" values.  As far as I know, it is not possible to bind a combobox directly to an enum property.  I'm assuming that your business object also stores the database id of the lookup item that was selected so that it can be persisted back to the database.  What I do is bind the combobox to this lookup id property on the business object.  Then in the get accessor of the enum property I call a static/shared helper method that "maps" the database id of the lookup item to the correct value in the enum.  So your get accessor for the enum property on the business object would look something like this (c#):


public MyEnum SomeColor

   get 
   { 
      return EnumHelper.GetMyEnumValue(m_colorId); 
   } 
}

The implementation is a little tedious, but it gets the job done.  It's also much better than looking at code like this:

if (m_colorId == 1)   && 1 stands for Red

If anybody knows a better way, please let us know.

Dustin

RockfordLhotka replied on Thursday, July 12, 2007

Why not wrap the enum in a NVL? In other words, create an object that inherits from NVLB, where the DataPortal_Fetch() method merely loads the list from the enum. You can enumerate the values in an enum (using reflection if nothing else).

Given an enum like

  public enum MyEnum
  {
    Red,
    Blue,
    Green
  }

You'd have a class like:

  [Serializable]
  public class MyEnumList : Csla.NameValueListBase<MyEnum,string>
  {
    public static MyEnumList GetList()
    {
      return Csla.DataPortal.Fetch<MyEnumList>(new Criteria(typeof(MyEnumList)));
    }

    private MyEnumList()
    { /* require use of factory method */ }

    [Csla.RunLocal]
    protected override void DataPortal_Fetch(object criteria)
    {
      this.IsReadOnly = false;
      foreach (MyEnum item in Enum.GetValues(typeof(MyEnum)))
        Add(new Csla.NameValueListBase<MyEnum, string>.NameValuePair(
          item, Enum.GetName(typeof(MyEnum), item)));
      this.IsReadOnly = true;
    }
  }

Then you can bind it like you'd bind any other object/list to a combobox, as long as the object's property is of type MyEnum:

    MyEnum _color;
    public MyEnum Color
    {
      [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
      get
      {
        CanReadProperty(true);
        return _color;
      }
      [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
      set
      {
        CanWriteProperty(true);
        if (!_color.Equals(value))
        {
          _color = value;
          PropertyHasChanged();
        }
      }
    }

 

rd_bigdog replied on Thursday, July 12, 2007

Hey Rocky,

In summary, that code worked perfectly. After analyzing my problem set more after I got a sample project working with it, I added a few requirements to my list. I follow the pattern you posted. But, in my case, I have a 'master' enum which is an enum of all the available enums that we have. When I say enums in this context I am referring to different domain of lookup values. So, I have an enum of all lookup value types, and enums of each individual lookup. In total, dozens upon dozens of enums -- lots of entities managed in this system.

So, I wanted to make your code sample generic so that I only had one class to deliver my lookups to the UI, and not one class per lookup/enum. I managed to get this to work, it wasn't too tricky, I will post the code here as I think the pattern might help others.

I have custom combobox that is dedicated to showing the lookup values based on the enums. I gave it a property with the type of the "master' enum so that a consumer can pick the lookup domain to popluate the box with:

Protected Overrides Sub OnCreateControl()

MyBase.OnCreateControl()

For Each bindings As System.Windows.Forms.Binding In DataBindings

bindings.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged

Next

If Not Me.DesignMode Then

 

Me.DataSource = AMSCSLA.ValueList.GetValueList(AMSDomain)

Me.DisplayMember = "Value"

Me.ValueMember = "Key"

End If

End Sub

Public Property AMSDomain() As AMS.Framework.AMSDomains

Get

Return _amsDomain

End Get

Set(ByVal value As AMS.Framework.AMSDomains)

_amsDomain = value

End Set

End Property

 

In here, pass the master domain type to my NVL. In my NL I do this:

 

Public Shared Function GetValueList(ByVal domain As AMS.Framework.AMSDomains) As ValueList

Return Csla.DataPortal.Fetch(Of ValueList)(New DomainCriteria(domain))

End Function

Protected Overloads Sub DataPortal_Fetch(ByVal thecriteria As DomainCriteria)

Me.IsReadOnly = False

Dim enumName As String = [Enum].GetName(GetType(AMSDomains), CType(thecriteria.Domain, Integer))

Dim enumTypeHandle As System.Runtime.Remoting.ObjectHandle = System.Activator.CreateInstance("AMS.Framework", "AMS.Framework.AMSDomainValues." & enumName)

Dim enumType As [Enum] = CType(enumTypeHandle.Unwrap(), [Enum])

For Each item As Object In [Enum].GetValues(enumType.GetType)

Add(New Csla.NameValueListBase(Of [Enum], String).NameValuePair( _

item, [Enum].GetName(enumType.GetType, item)))

Next

Me.IsReadOnly = True

End Sub

Protected Class DomainCriteria

Public Property Domain() As AMS.Framework.AMSDomains

Get

Return _domain

End Get

Set(ByVal value As AMS.Framework.AMSDomains)

_domain = value

End Set

End Property

Private _domain As AMS.Framework.AMSDomains

Public Sub New(ByVal domain As AMS.Framework.AMSDomains)

_domain = domain

End Sub

End Class

End Class

 

I use a little reflection to create an insance of the type of enum specified by the domain (this makes a requirment that the text of the master domain match the actual domain, but that will be managable). I will have left to do after this is add in a call to my lookup table to get the string text for the NVL in the users culture so the UI displays correctly and to sort the values by that text.

 

Thanks very much for your post, you definitely got me down the right path.

 

Regards,

 

Rick.

dshafer replied on Friday, July 13, 2007

Wow.  That's a pretty good idea.  I'll have to try to modify my system to use something like this.  It's quite a bit less tedious than what I'm currently using.

Dustin

Dave Boal replied on Wednesday, April 02, 2008

Here's another suggestion:

I created a class called EnumNVL which creates a NameValueList from any Enum Type.

Sample Usage in form:

EnumNVL envlDateRangeTypes = EnumNVL.GetEnumNVL(typeof(DateRangeType));
// The parameter for the GetEnumNVL() method is any valid Enum, ie., GetEnumNVL(typeof(AnyValidEnum)).
// The substitutable parameter in this example uses the Enum type "DateRangeType".

cbxDateRangeTypes.DataSource = envlDateRangeTypes
cbxDateRangeTypes.DisplayMember = "Value";
cbxDateRangeTypes.ValueMember = "Key";
cbxDateRangeTypes.SelectedIndex = 0;

Here's is the EnumNVL class:

[Serializable]
public class EnumNVL : Csla.NameValueListBase<Enum, string>
{
   
private static Type _Type = null;
   
public static EnumNVL GetEnumNVL(Type type)
   
{
      
_Type = type;
      
return Csla.DataPortal.Fetch<EnumNVL>(new Criteria(typeof(EnumNVL)));
   }

   private EnumNVL()
   
{ /* require use of factory method */ }

   [Csla.RunLocal]
   protected override void DataPortal_Fetch(object criteria)
   {
      
this.IsReadOnly = false;
      
foreach (Enum item in Enum.GetValues(_Type))
         Add(new Csla.NameValueListBase<Enum, string>.NameValuePair(
            
item, Enum.GetName(_Type, item)));
      
this.IsReadOnly = true;
   }
}

-- Update:

Cine's brilliant generic version below is a great modification. Here is an example of how I use his code:

EnumNVL<DateRangeType> enumNVL = EnumNVL<DateRangeType>.GetEnumNVL();

// The KEY POINT is that with your more general code, I can cast the type to int as follows:
int dbColumnValue = (int)enumNVL[0].Key;

// I could not do that cast with my code!

Cine replied on Wednesday, April 02, 2008

Even more general:

   class Program
   {
      static void Main(string[] args)
      {
         foreach (NameValueListBase<hest, string>.NameValuePair s in HestNVL.GetEnumNVL())
            Console.WriteLine(string.Format("{0} {1}", (int)s.Key, s.Value));
      }
   }
   [Serializable]
   public class EnumNVL<T> : NameValueListBase<T, string>
   {
      public static EnumNVL<T> GetEnumNVL()
      {
         return DataPortal.Fetch<EnumNVL<T>>(new Criteria(typeof(T)));
      }

      protected EnumNVL()
      { /* require use of factory method */ }

      [RunLocal]
      protected override void DataPortal_Fetch(object criteria)
      {
         Criteria c = (Criteria)criteria;
         IsReadOnly = false;
         foreach (T item in Enum.GetValues(c.ObjectType))
            Add(new NameValuePair(item, Enum.GetName(c.ObjectType, item)));
         IsReadOnly = true;
      }
   }
   [Serializable]
   public enum hest
   {
      red,
      green
   }
   [Serializable]
   public class HestNVL : EnumNVL<hest> { }

JoeFallon1 replied on Thursday, April 03, 2008

Thanks!

Here it is in VB:

<Serializable()> _
Public Class EnumNVL
 
Inherits NameValueListBase(Of [Enum], String)

  Private Shared mType As Type = Nothing

#Region " Constructor "

  Private Sub New()
 
  'require use of factory methods 
  End Sub

#End Region

#Region " Factory Methods "

  Public Shared Function GetEnumNVL(ByVal type As Type) As EnumNVL
    mType = type
   
Return DataPortal.Fetch(Of EnumNVL)(New Criteria(GetType(EnumNVL)))
 
End Function

#End Region

#Region " Data Access "

  <RunLocal()> _
 
Protected Overrides Sub DataPortal_Fetch(ByVal criteria As Object)
    RaiseListChangedEvents =
False
   
IsReadOnly = False

   
For Each item As [Enum] In [Enum].GetValues(mType)
      Add(
New NameValuePair(item, [Enum].GetName(mType, item)))
   
Next

    IsReadOnly = True
   
RaiseListChangedEvents = True
 
End Sub

#End Region

End Class

 

pillesoft replied on Friday, April 25, 2008

Dear All,

these examples are really usefull for me also. i would like to share some extension. if you would like to localize enum valus here is a possible solution:
create an attribute class:
  /// <summary>
  /// Provides a description for an enumerated type.
  /// </summary>
  [AttributeUsage(AttributeTargets.Enum | AttributeTargets.Field,
   AllowMultiple = false)]
  public sealed class EnumDescriptionAttribute : Attribute
  {
    private string description;

    /// <summary>
    /// Gets the description stored in this attribute.
    /// </summary>
    /// <value>The description stored in the attribute.</value>
    public string Description
    {
      get
      {
        return this.description;
      }
    }

    /// <summary>
    /// Initializes a new instance of the
    /// <see cref="EnumDescriptionAttribute"/> class.
    /// </summary>
    /// <param name="description">The description to store in this attribute.
    /// </param>
    public EnumDescriptionAttribute(string description)
      : base()
    {
      this.description = description;
    }
  }

these attributes can be used :
  [Serializable()]
  public enum PUType
  {
    [EnumDescription("Installation")]
    INSTALLATION = 1,
    [EnumDescription("Material")]
    MATERIAL = 2,
    [EnumDescription("Optional")]
    OPTIONAL = 3
  }

and here is a method to extend EnumNVL<T> class:
    private string GetDescription(object enumname)
    {
      if (enumname == null)
      {
        throw new ArgumentNullException("enumname");
      }

      string description = null;
      FieldInfo fieldinfo = typeof(T).GetField(enumname.ToString());
      EnumDescriptionAttribute[] attributes =
         (EnumDescriptionAttribute[])
       fieldinfo.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);

      if (attributes != null && attributes.Length > 0)
      {
        description = attributes[0].Description;
      }
      return description;
    }

and of course modify the Add method:
        Add(new NameValuePair(item, GetDescription(item)));

hope this helps to someone, however i got the basic idea from codeproject.com
Ivan

pillesoft replied on Friday, April 25, 2008

some adjustment of GetDescription method:

      if (attributes != null && attributes.Length > 0)
      {
        description = attributes[0].Description;
      }
      else
        description = Enum.GetName(typeof(T), enumname);


Ivan

pillesoft replied on Friday, April 25, 2008

Dear All,

i need your help now:
one of my enums Description contains space:
  [Serializable()]
  public enum PUDimension
  {
    [EnumDescription("Quantity Only")]
    QUANTITY = 0,
    [EnumDescription("Length")]
    LENGTH = 1,
    [EnumDescription("Square Meter")]
    SQUARE_METER = 2,
    [EnumDescription("Cubic Meter")]
    CUBIC_METER = 3
  }

if this enum is bounded to a combobox, and when i select those where there is a space in the description i receive an error like:
Quantity Only is not valid value for PUDimension
when i select Length
the system accepts.

this is the combobox binding:
      PmsEnumNVL<PUDimension> nvlpudimen = PUDimensionNVL.GetEnumNVL();
      this.dimensionComboBox.DataSource = nvlpudimen;
      this.dimensionComboBox.DisplayMember = "Value";
      this.dimensionComboBox.ValueMember = "Key";

how to tell the system that SelectedItem.Key property needs to be used?

Ivan

Fintanv replied on Friday, April 25, 2008

What about the simple solution of replacing the spaces with an underscore?

pillesoft replied on Sunday, April 27, 2008

Dear All,

the first idea of this Description Attribute was to localize enum valus. it is important for me as i'm hungarian.
in the meantime, after reading some articles i've found a solution.
what i implemented is the typeconverter.
if you are interested in please check http://www.codeproject.com/KB/cs/LocalizingEnums.aspx

Ivan

Shazam replied on Tuesday, October 21, 2008

This class is totally unnecessary.  There already is a Description attribute that does pretty well what this does.

Decorate your enum:

using System;
using System.ComponentModel;

[Serializable]
public enum SomeEnum
{
    Active = 1,
    [Description("Here's An Enum That Could Use Some Spaces")]
    HeresAnEnumThatCouldUseSomeSpaces = 2,
    Inactive = 9
}

I then have a Enum helper class:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

/// <summary>
/// An Enum helper class.
/// </summary>
/// <typeparam name="T">An enumeration.</typeparam>
public static class Enum<T>
{
    /// <summary>
    /// Returns a Dictionary with the Enumeration as the Key, and the Description as the Value.
    /// </summary>
    /// <returns></returns>
    public static Dictionary<T, string> GetValues()
    {
        var values = new Dictionary<T,string>(Enum.GetNames(typeof(T)).Length);

        foreach (T t in Enum.GetValues(typeof(T)))
        {
            values.Add(t, Description(t));
        }

        return values;
    }

    public static string Description(T value)
    {
        var da = (DescriptionAttribute[])(typeof(T).GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false));

        return da.Length > 0 ? da[0].Description : value.ToString();
    }

    public static T FromDescription(string description)
    {
        foreach (T t in Enum.GetValues(typeof(T)))
        {
            if (Description(t).Equals(description) || t.ToString().Equals(description))
            {
                return t;
            }
        }

        throw new ArgumentOutOfRangeException(string.Format("The description \"{0}\" was not found in the enumeration.", description));
    }

    public static T Parse(string value)
    {
        return (T)Enum.Parse(typeof(T), value);
    }

    public static string ValueToString<C>(T value)
    {
        return Convert.ChangeType(value, typeof(C)).ToString();
    }
}
Use the Enum<T>.GetValues() method for control binding.  For dropdowns, use "Key" as the DataValueField and "Value" as the DataTextField.

I don't even bother with the NameValuePair collection if they're to represent enums.

Oh, and I take zero credit for this code.  I found it somewhere on the interweb.

RockfordLhotka replied on Tuesday, October 21, 2008

That’s a good idea – using the Description attribute.

 

However, a Dictionary isn’t a valid data binding source, so there’s probably still some value in having a list type that is bindable that auto-populates based on the enum type. Perhaps a subclass of NameValueListBase that wraps your code in its DataPortal_Fetch() method?

 

Rocky

Shazam replied on Wednesday, October 22, 2008

Hmm, Dictionary<K, V> does implement IEnumerable.  Why isn't it valid? Is that a WPF or Winforms issue?  It works fine with the <csla:CslaDataSource> tag.

RockfordLhotka replied on Wednesday, October 22, 2008

Web Forms has a very low set of requirements for its binding sources. Windows Forms, WPF and Silverlight have richer functionality, and thus have a higher set of requirements.

 

Rocky

 

Shazam replied on Wednesday, October 22, 2008

Tells you how much non-Webforms stuff I do :)

Certainly, it's easy enough to wrap the descriptive enum values into a NameValueListBase.

Patrick.Roeper replied on Tuesday, April 29, 2008

@Cine & Joe:

I implemented your generic version of the solution Rocky offered, and I am getting very strange behavior in my projects. Whenever I have an implementation of EnumNVL<T> in one of my business object libraries, I can no longer see that assembly in the "Configure Datasource" popup in order to hookup data binding... I havent changed any references or anything, the assembly just automagically becomes unlisted.

However, whenever I make an explicit implementation like Rocky showed, I can see the business object assembly in my "Configure Datasource" window and everything works as normal.

Can you think of a reason why the generic version would cause this problem?

----

Update: I was able to get everything working by modifying the previously posted generic code. Here is the version that doesn't cause the behavior described above:

   [Serializable]
    public class EnumNVL<T> : NameValueListBase<T, string>
    {
        private static EnumNVL<T> cache;

        protected EnumNVL()
        {
            // Require factory method call from derived type
        }

        public static EnumNVL<T> GetList()
        {
            if (cache == null)
                cache = DataPortal.Fetch<EnumNVL<T>>(new Criteria(typeof(EnumNVL<T>)));

            return cache;
        }

        [RunLocal]
        protected override void DataPortal_Fetch(object criteria)
        {
            IsReadOnly = false;

            foreach (T item in Enum.GetValues(typeof(T)))
                Add(new NameValuePair(item, Enum.GetName(typeof(T), item)));

            IsReadOnly = true;
        }
    }

Fintanv replied on Wednesday, April 30, 2008

Can we get this added to the FAQ so it doesn't get burried over time?

lprada replied on Thursday, July 12, 2007

How do you bounf to the selecedvalue of the combo?

rd_bigdog replied on Thursday, July 12, 2007

I am binding using the propeties window - Data - Data Bindings - SelectedValue and setting the SelectedValue to MyBOBindingSource.PropertyName.

So, from the SelectedValue property under data bindings, a data source has been created bound to my business object. I then use this binding source to bind to all the controls.

Copyright (c) Marimer LLC