<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Deborah's Developer MindScape : CSharp, Enum</title><link>http://msmvps.com/blogs/deborahk/archive/tags/CSharp/Enum/default.aspx</link><description>Tags: CSharp, Enum</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Enum.TryParse</title><link>http://msmvps.com/blogs/deborahk/archive/2010/08/09/enum-tryparse.aspx</link><pubDate>Tue, 10 Aug 2010 06:36:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1775651</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1775651</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2010/08/09/enum-tryparse.aspx#comments</comments><description>&lt;p&gt;If you work with Enum values, you may often need to convert between the Enum, an integer representation of the Enum (to store in a table for example), and the string representation of the Enum (to display to the user for example). .NET 4.0 makes this easier with the new TryParse method.&lt;/p&gt;  &lt;p&gt;This example uses a CustomerTypeOption Enum value.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public enum CustomerTypeOption     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Customer type is unknown      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unknown = 0, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Customer is an individual      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Individual = 1, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Customer is a corporation      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Corporation = 2, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Customer is an educational institution      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Education = 3, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// Customer is a government agency.      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /// &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Government = 4      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Enum CustomerTypeOption     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; Customer type is unknown      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unknown = 0 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; Customer is an individual      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Individual = 1 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; Customer is a corporation      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Corporation = 2 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; Customer is an educational institution      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Education = 3 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; Customer is a government agency.      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39;&amp;#39;&amp;#39; &amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Government = 4      &lt;br /&gt;End Enum&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The Enum defines the valid types of customers supported in an application.&lt;/p&gt;  &lt;p&gt;The TryParse method takes either the integer value (converted to a string) OR the string value and converts it to the Enum type as shown below.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;int i = 1;     &lt;br /&gt;string value = i.ToString();      &lt;br /&gt;CustomerTypeOption customerType;      &lt;br /&gt;if (Enum.TryParse(value, out customerType))      &lt;br /&gt;{ /* Success */ }      &lt;br /&gt;else      &lt;br /&gt;{ /* Failure */ } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;value = &amp;quot;individual&amp;quot;;     &lt;br /&gt;if (Enum.TryParse(value, true, out customerType))      &lt;br /&gt;{ /* Success */ }      &lt;br /&gt;else      &lt;br /&gt;{ /* Failure */ }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim i As Integer = 1     &lt;br /&gt;Dim value As String = i.ToString()      &lt;br /&gt;Dim customerType As CustomerTypeOption      &lt;br /&gt;If ([Enum].TryParse(value, customerType)) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Success */      &lt;br /&gt;Else      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Failure       &lt;br /&gt;End If &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;value = &amp;quot;individual&amp;quot;     &lt;br /&gt;If ([Enum].TryParse(value, True, customerType)) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Success       &lt;br /&gt;Else      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Failure      &lt;br /&gt;End If&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In the first example, the integer 1 is converted to a string and passed as the first parameter to the TryParse method. A variable of the desired Enum type is passed in as the second parameter and is defined as an output parameter (using the out keyword in C#). &lt;/p&gt;  &lt;p&gt;If the TryParse succeeds, the method returns true and the converted value is returned in the output parameter. If the method fails, it returns false.&lt;/p&gt;  &lt;p&gt;In the second example, the string &amp;quot;individual&amp;quot; is passed as the first parameter. The second parameter is set to true, telling the TryParse method to ignore the case of the first parameter. This allows &amp;quot;individual&amp;quot; to match &amp;quot;Individual&amp;quot; even if the casing is different. The third parameter is then the output parameter.&lt;/p&gt;  &lt;p&gt;Use &lt;strong&gt;TryParse&lt;/strong&gt; any time you need to convert from an integer value or string representation to an Enum value.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1775651" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Enum/default.aspx">Enum</category></item><item><title>Silverlight and RIA: Enum Properties</title><link>http://msmvps.com/blogs/deborahk/archive/2009/11/10/silverlight-and-ria-enum-properties.aspx</link><pubDate>Tue, 10 Nov 2009 20:58:58 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1738861</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1738861</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/11/10/silverlight-and-ria-enum-properties.aspx#comments</comments><description>&lt;p&gt;I mentioned in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/11/10/silverlight-and-ria-ignoring-a-property-in-your-business-object.aspx" target="_blank"&gt;this prior post&lt;/a&gt; that RIA Services did not know how to handle properties that have an Enum data type. The problem is not really that RIA Services does not know how to handle the properties; rather it does not have any knowledge of the Enum itself.&lt;/p&gt;  &lt;p&gt;Take this example.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public enum CustomerTypeOption      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Consumer,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Corporation,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Education,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Government       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;private CustomerTypeOption _CustomerType;      &lt;br /&gt;public CustomerTypeOption CustomerType {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return _CustomerType; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; set { _CustomerType = value; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Enum CustomerTypeOption      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Consumer       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Corporation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Education       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Government       &lt;br /&gt;End Enum&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _CustomerType As CustomerTypeOption      &lt;br /&gt;Public Property CustomerType() As CustomerTypeOption       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _CustomerType       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As CustomerTypeOption)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerType = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This code resides in a Customer class like the one &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/11/05/silverlight-ria-services-and-your-business-objects.aspx"&gt;shown in this prior post&lt;/a&gt;. If you create a CustomerService domain services class, Silverlight will generate a proxy class containing all of the Customer class properties. However, the generated code contains a syntax error because it does not understand the CustomerTypeOption type.&lt;/p&gt;  &lt;p&gt;This problem can be solved by sharing the Enum with Silverlight following the technique detailed in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/11/10/silverlight-and-ria-sharing-your-business-object-files.aspx" target="_blank"&gt;this prior post&lt;/a&gt; and shown below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0334.image_5F00_4F8E5FB2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5127.image_5F00_thumb_5F00_3862E534.png" width="483" height="363" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let&amp;#39;s go through the steps in detail:&lt;/p&gt;  &lt;p&gt;1. Add a new file to your business object component and call it Customer&lt;strong&gt;.shared.vb&lt;/strong&gt; (if your component is VB.NET) or Customer&lt;strong&gt;.shared.cs&lt;/strong&gt; (if you are using C#).&lt;/p&gt;  &lt;p&gt;2. Add the &lt;strong&gt;partial&lt;/strong&gt; keyword to the class name in the file as shown in the code below.&lt;/p&gt;  &lt;p&gt;3. Cut the Enum definition from the Customer class and paste it into this partial class.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public partial class Customer     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public enum CustomerTypeOption      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Consumer,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Corporation,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Education,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Government      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Partial Public Class Customer &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Enum CustomerTypeOption     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Consumer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Corporation      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Education      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Government      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Enum &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;4. Right click on the Web project linked to your Silverlight project and select Add | Existing Item.&lt;/p&gt;  &lt;p&gt;5. In the Add Existing Item dialog, select the file and select &lt;strong&gt;Add As Link&lt;/strong&gt; from the Add button drop down menu.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0827.image_5F00_083B9A71.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0250.image_5F00_thumb_5F00_2E9D7DBC.png" width="477" height="85" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This links the file between your business object class library project and the Web project linked to your Silverlight project.&lt;/p&gt;  &lt;p&gt;6. Build the solution.&lt;/p&gt;  &lt;p&gt;Silverlight should now have a copy of the Customer.shared.vb or Customer.shared.cs file under the Generated_Code node. Since the Enum is now defined in the Silverlight project, your CustomerType property in the generated code should compile without errors.&lt;/p&gt;  &lt;p&gt;Use this technique any time you want to share an Enum between your business object class library project and your Silverlight project.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738861" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Enum/default.aspx">Enum</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/RIA+Services/default.aspx">RIA Services</category></item><item><title>Building a Business Object Base Class</title><link>http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx</link><pubDate>Tue, 21 Jul 2009 18:49:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1704681</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1704681</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx#comments</comments><description>&lt;p&gt;If you are building applications in .NET to manage data for a business, you are most likely creating business object classes. Depending on the business, these classes could include Customer, Product, Order, Invoice, PurchaseOrder, Employee, TimeCard and so on.&lt;/p&gt;  &lt;p&gt;A simple sample Customer class is shown &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/03/generics-building-a-list-of-customers.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There are some features that all business objects need to support. For example:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Entity State: The business object needs to track whether it is new, updated, or deleted so it can make the appropriate change to the database. &lt;/li&gt;    &lt;li&gt;Validation: Is the current data defined for the business object valid? &lt;/li&gt;    &lt;li&gt;Save: Saves the changes to the database. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Notice that data retrieval functionality is not included in this list. That is because in most cases, you may never retrieve a single business object. Rather, you would retrieve a set of them. For example, all active orders or all customers with overdue invoices. So the retrieve functionality is not included in the class that manages a single object. (Most on this in a later post.)&lt;/p&gt;  &lt;p&gt;Instead of repeating this common functionality in each business object, it makes sense to build a base class. Each business object can then inherit from this base class to share this common functionality.&lt;/p&gt;  &lt;p&gt;So let’s get started.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;using System;      &lt;br /&gt;using System.ComponentModel;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public abstract class BoBase :      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IDataErrorInfo,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; INotifyPropertyChanged       &lt;br /&gt;{       &lt;br /&gt;      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Imports System.ComponentModel      &lt;br /&gt;      &lt;br /&gt;Public MustInherit Class BOBase       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Implements INotifyPropertyChanged       &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The class is abstract (MustInherit in VB) to indicate that it is meant to be a base class and not to be used on its own. An abstract class cannot be instantiated directly, so no other code can create an instance of the class.&lt;/p&gt;  &lt;p&gt;The class then implements two interfaces:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;IDataErrorInfo: This interface provides error information that the user interface can use to report validation errors to the user. It works well with the ErrorProvider control provided in WinForms and supports ASP.NET and WPF features. &lt;/li&gt;    &lt;li&gt;INotifyPropertyChanged: This interface ensures that the user interface is notified when a property value changes, keeping your business object and user interface in sync. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We’ll look at the implementation of these interfaces shortly.&lt;/p&gt;  &lt;p&gt;First, define the valid set of entity states.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal enum EntityStateType      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unchanged,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Added,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Deleted,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Modified       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Enum EntityStateType      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Unchanged       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Added       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Deleted       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Modified       &lt;br /&gt;End Enum&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The Enum is declared Protected because the entity state should only be accessible from the business object itself. However, Internal (Friend in VB) was added so that related objects (such as Order and OrderLineItem) could reference the related object state.&lt;/p&gt;  &lt;p&gt;The business object state is retained using an EntityState property.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected EntityStateType EntityState { get; private set; }&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _EntityState As EntityStateType      &lt;br /&gt;Protected Property EntityState() As EntityStateType       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _EntityState       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private Set(ByVal value As EntityStateType)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _EntityState = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This property is protected, but the setter is private. So the business objects that inherit from this class can read the entity state, but only the base class can set the value.&lt;/p&gt;  &lt;p&gt;Additional properties provide a way to get the entity’s state in an easier fashion. These properties are not required, but they make the base class a little easier to use.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsDirty       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return this.EntityState != EntityStateType.Unchanged; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsNew       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return this.EntityState == EntityStateType.Added; }       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BindableAttribute(False)&amp;gt; _      &lt;br /&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _       &lt;br /&gt;Public ReadOnly Property IsDirty() As Boolean       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return Me.EntityState &amp;lt;&amp;gt; EntityStateType.Unchanged       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BindableAttribute(False)&amp;gt; _      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _      &lt;br /&gt;Public ReadOnly Property IsNew() As Boolean       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return Me.EntityState = EntityStateType.Added       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The IsDirty and IsNew properties are public, so they can be accessed from anywhere. They are marked with two attributes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bindable: Defines whether the property should be used for binding. In this case the value is false because the user interface should not be able to bind to this property. &lt;/li&gt;    &lt;li&gt;Browsable: Defines whether the property should be displayed in the Properties window. Again, the value is false. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Two other properties handle the validation.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BindableAttribute(false)]      &lt;br /&gt;[BrowsableAttribute(false)]       &lt;br /&gt;public bool IsValid       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return (ValidationInstance.Count == 0); }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected Validation ValidationInstance { get; set; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;lt;Bindable(False)&amp;gt; _&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;lt;BrowsableAttribute(False)&amp;gt; _     &lt;br /&gt;Public ReadOnly Property IsValid() As Boolean     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return (ValidationInstance.Count = 0)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get     &lt;br /&gt;End Property &lt;/font&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _ValidationInstance As Validation      &lt;br /&gt;Protected Property ValidationInstance() As Validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _ValidationInstance       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Private Set(ByVal value As Validation)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _ValidationInstance = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Again, the public property is marked with the Browsable and Bindable attributes. The ValidationInstance property retains an instance of the Validation class for the business object. The code for the Validation class is &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/16/validation-class.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The constructor creates an instance of the Validation class.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected BoBase()      &lt;br /&gt;{&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160; ValidationInstance = new Validation();       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Sub New()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ValidationInstance = New Validation      &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The following is the implementation of IDataErrorInfo.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#region IDataErrorInfo Members &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BrowsableAttribute(false)]      &lt;br /&gt;[BindableAttribute(false)]       &lt;br /&gt;public string Error       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return ValidationInstance.ToString(); }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[BrowsableAttribute(false)]      &lt;br /&gt;[BindableAttribute(false)]       &lt;br /&gt;public string this[string columnName]       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return ValidationInstance[columnName]; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#endregion&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#Region &amp;quot; Properties required by the IDataErrorInfo&amp;quot;      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Bindable(False)&amp;gt; _&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BrowsableAttribute(False)&amp;gt; _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public ReadOnly Property [Error]() As String _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo.Error       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return ValidationInstance.ToString       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BrowsableAttribute(False)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Bindable(False)&amp;gt; _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Default Protected ReadOnly Property Item(ByVal columnName _&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; As String) As String _&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements IDataErrorInfo.Item       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return ValidationInstance.Item(columnName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property       &lt;br /&gt;      &lt;br /&gt;#End Region&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Error&lt;/strong&gt; property uses the overridden ToString method of the validation class to return the full list of validation errors.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Item&lt;/strong&gt; property provides access to the validation errors given a property name. This property is implemented as the class indexer in C#.&lt;/p&gt;  &lt;p&gt;The following in the implementation of INotifyPropertyChanged.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#region INotifyPropertyChanged Members     &lt;br /&gt;public event PropertyChangedEventHandler PropertyChanged;      &lt;br /&gt;#endregion&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;#Region &amp;quot; Events required by INotifyPropertyChanged&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Event PropertyChanged(ByVal sender As Object, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ByVal e As System.ComponentModel.PropertyChangedEventArgs) _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Implements INotifyPropertyChanged.PropertyChanged      &lt;br /&gt;#End Region&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This interface only defines a single event. This event should be raised whenever the data is changed.&lt;/p&gt;  &lt;p&gt;Since every business object will have unique requirements for the save operation, the &lt;strong&gt;SaveItem&lt;/strong&gt; method is not implemented. Rather it is defined as abstract.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public abstract Boolean SaveItem();&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public MustOverride Function SaveItem() As Boolean&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Defining an abstract (MustOverride in VB) SaveItem method ensures that every business object has a SaveItem method.&lt;/p&gt;  &lt;p&gt;Finally, since the EntityState property setter is private, the base class needs a method to set the entity state.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal void SetEntityState(EntityStateType newEntityState)     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; switch (newEntityState)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Deleted:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Unchanged:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; case EntityStateType.Added:      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.EntityState = newEntityState;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; default:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (this.EntityState == EntityStateType.Unchanged)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.EntityState = newEntityState;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;protected internal void SetEntityState(EntityStateType newEntityState, string propertyName)     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetEntityState(newEntityState);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (PropertyChanged != null)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PropertyChanged(this,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;new PropertyChangedEventArgs(propertyName));     &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Sub SetEntityState(ByVal dataState As EntityStateType)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetEntityState(dataState, Nothing)      &lt;br /&gt;End Sub &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Protected Friend Sub SetEntityState( _     &lt;br /&gt; ByVal newEntityState As EntityStateType, ByVal propertyName As String)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Select Case newEntityState      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Case EntityStateType.Deleted, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EntityStateType.Unchanged, _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EntityStateType.Added      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.EntityState = newEntityState &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Case Else     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If Me.EntityState = EntityStateType.Unchanged Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Me.EntityState = newEntityState      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Select &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; If Not String.IsNullOrEmpty(propertyName) Then     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim e As New PropertyChangedEventArgs(propertyName)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RaiseEvent PropertyChanged(Me, e)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;SetEntityState&lt;/strong&gt; method has two overloads. The first is used when changing the entity state in general and the second is used when changing the entity state because a specific property is changed.&lt;/p&gt;  &lt;p&gt;For example, when setting an object as Unchanged, Added, or Deleted, it does not matter which property was changed. But when a particular property is changed, the code must also raise the PropertyChanged event.&lt;/p&gt;  &lt;p&gt;In this case, the C# and VB code was implemented differently. In the C# code, the code to set the entity state is in the first overload. The second overload then calls the first and then raises the event.&lt;/p&gt;  &lt;p&gt;In the VB code, the first overload simply calls the second overload. The second overload then sets the entity state and then raises the event as appropriate. You can use either technique in either language.&lt;/p&gt;  &lt;p&gt;That’s it! You now have a base class that can be used with any business object class. If you have any other common functionality, you can add it to this base class. &lt;/p&gt;  &lt;p&gt;Here is an example of how you use this base class.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public class Customer : BoBase     &lt;br /&gt;{      &lt;br /&gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private string _LastName;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string LastName      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _LastName; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName == null || _LastName != value)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;LastName&amp;quot;;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Validate the last name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateClear(propertyName);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateRequired(propertyName, value); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, propertyName);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public override Boolean SaveItem()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // TODO: Add code here      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class Customer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Inherits BoBase&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _LastName As String     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property LastName() As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _LastName      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName Is Nothing OrElse _LastName &amp;lt;&amp;gt; value Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;LastName&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Validate the last name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateClear(propertyName)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValidationInstance.ValidateRequired(propertyName, value) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, propertyName)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Public Overrides Function SaveItem() As Boolean     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; TODO: Add code here      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Function      &lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Notice how the class statement includes the syntax to inherit from BoBase. The LastName property uses the ValidationInstance defined in the base class to validate the value. It also sets the entity state when the last name is changed.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1704681" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/OOP/default.aspx">OOP</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Enum/default.aspx">Enum</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Binding/default.aspx">Binding</category></item><item><title>Enum: Binding to the Description Attribute</title><link>http://msmvps.com/blogs/deborahk/archive/2009/07/10/enum-binding-to-the-description-attribute.aspx</link><pubDate>Fri, 10 Jul 2009 23:31:04 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1699394</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1699394</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/07/10/enum-binding-to-the-description-attribute.aspx#comments</comments><description>&lt;p&gt;The Enum keyword allows you to define a standard set of named constants for use in your application. Sometimes you may want to present this same list of&amp;#160; values to your user. &lt;/p&gt;  &lt;p&gt;You can display the set of Enum values in a ComboBox or ListBox using data binding. And even better, if you use the DescriptionAttribute in the Enum, you can display a more user-friendly set of values.&lt;/p&gt;  &lt;p&gt;For example, a Customer business object may have a CustomerType defined with a specific set of options for corporations, individuals, schools, and charities. You want to use these values in your code, but also display them to the user in a ComboBox.&lt;/p&gt;  &lt;h2&gt;Enum Definition&lt;/h2&gt;  &lt;p&gt;The Enum can reside in the Customer class, or in its own class.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public enum CustomerTypeOption      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; NotDefined,&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Corp,&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; IndividualorFamily,&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; SchoolorUniversity,&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Charity      &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Enum CustomerTypeOption      &lt;br /&gt;&amp;#160;&amp;#160; NotDefined       &lt;br /&gt;&amp;#160;&amp;#160; Corp       &lt;br /&gt;&amp;#160;&amp;#160; IndividualorFamily       &lt;br /&gt;&amp;#160;&amp;#160; SchoolorUniversity       &lt;br /&gt;&amp;#160;&amp;#160; Charity       &lt;br /&gt;End Enum&lt;/font&gt;&lt;/p&gt;  &lt;h2&gt;CustomerType Property&lt;/h2&gt;  &lt;p&gt;A CustomerType property in the Customer class can use this enum type.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;public CustomerTypeOption CustomerType { get; set; }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _CustomerType As CustomerTypeOption      &lt;br /&gt;Public Property CustomerType() As CustomerTypeOption       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _CustomerType       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As CustomerTypeOption)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerType = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The C# code uses the automatically implemented properties feature introduced with .NET 3.5. The VB code uses the full property definition.&lt;/p&gt;  &lt;h2&gt;Binding To an Enum&lt;/h2&gt;  &lt;p&gt;The Enum can also be used by the user interface. For example, you can bind a comboBox or listBox to a set of customer type options.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dictionary&amp;lt;string, int&amp;gt; CustomerTypeList =      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new Dictionary&amp;lt;string, int&amp;gt;();       &lt;br /&gt;      &lt;br /&gt;foreach (int enumValue in       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Enum.GetValues(typeof(Customer.CustomerTypeOption)))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;Enum.GetName(typeof(Customer.CustomerTypeOption),      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; enumValue ), enumValue);       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;// Bind the customer type combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.DataSource = new BindingSource(CustomerTypeList,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; null);&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim CustomerTypeList As New Dictionary(Of String, Integer)      &lt;br /&gt;      &lt;br /&gt;For Each enumValue As Integer In _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Enum].GetValues(GetType(Customer.CustomerTypeOption))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add( _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Enum].GetName(GetType(Customer.CustomerTypeOption), _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; enumValue), enumValue)       &lt;br /&gt;Next &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39; Bind the combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.DataSource = New BindingSource(CustomerTypeList, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Nothing)&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This code defines a Dictionary to contain the name of the enum and the integer value of the enum. The for/each loop iterates through the set of Enum values and adds the name and value to the dictionary.&lt;/p&gt;  &lt;p&gt;The code then binds to the ComboBox, setting the DisplayMember to the “Key” of the dictionary and the ValueMember to the “Value” of the Dictionary.&lt;/p&gt;  &lt;p&gt;The result looks like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7853.image_5F00_2296F6DF.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0511.image_5F00_thumb_5F00_6BBCA298.png" width="236" height="96" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;While it does provide the appropriate options, it is not very user-friendly. It would be nicer if there were appropriate spaces and full words. For that, you can use the DescriptionAttribute on the Enum.&lt;/p&gt;  &lt;h2&gt;Using the DescriptionAttribute&lt;/h2&gt;  &lt;p&gt;NOTE: Be sure to import the &lt;strong&gt;System.ComponentModel&lt;/strong&gt; and the &lt;strong&gt;System.Reflection&lt;/strong&gt; namespaces.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public enum CustomerTypeOption      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [DescriptionAttribute(&amp;quot;Not Specified&amp;quot;)]       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; NotDefined, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; [DescriptionAttribute(&amp;quot;Corporation&amp;quot;)]      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Corp, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; [DescriptionAttribute(&amp;quot;Individual or Family&amp;quot;)]      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; IndividualorFamily, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; [DescriptionAttribute(&amp;quot;School or University&amp;quot;)]      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SchoolorUniversity, &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; [DescriptionAttribute(&amp;quot;Charity&amp;quot;)]      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Charity       &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Enum CustomerType      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DescriptionAttribute(&amp;quot;Corporate Customer&amp;quot;)&amp;gt; _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CorpCustomer &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DescriptionAttribute(&amp;quot;Individual or Family&amp;quot;)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; IndividualorFamily &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DescriptionAttribute(&amp;quot;School or University&amp;quot;)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SchoolorUniversity &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DescriptionAttribute(&amp;quot;Charity&amp;quot;)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Charity &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;DescriptionAttribute(&amp;quot;Kingdom&amp;quot;)&amp;gt; _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Kingdom       &lt;br /&gt;End Enum&lt;/font&gt; &lt;/p&gt;  &lt;h2&gt;Binding to an Enum Description&lt;/h2&gt;  &lt;p&gt;Now you can bind to the description instead of to the Enum constant.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;Dictionary&amp;lt;string, int&amp;gt; CustomerTypeList =      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new Dictionary&amp;lt;string, int&amp;gt;(); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;FieldInfo fi;      &lt;br /&gt;DescriptionAttribute da;       &lt;br /&gt;foreach (Customer.CustomerTypeOption enumValue in       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Enum.GetValues(typeof(Customer.CustomerTypeOption)))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; fi = typeof(Customer.CustomerTypeOption).       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetField((enumValue.ToString()));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(DescriptionAttribute));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (da != null)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add(da.Description, (int)enumValue);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;// Bind the customer type combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.DataSource = new BindingSource(CustomerTypeList,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; null);&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim CustomerTypeList As New Dictionary(Of String, Integer)      &lt;br /&gt;      &lt;br /&gt;Dim fi As FieldInfo       &lt;br /&gt;Dim da As DescriptionAttribute       &lt;br /&gt;For Each enumValue As Customer.CustomerTypeOption In _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Enum].GetValues(GetType(Customer.CustomerTypeOption))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; fi = GetType(Customer.CustomerTypeOption). _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetField(enumValue.ToString)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; da = DirectCast(Attribute.GetCustomAttribute(fi, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetType(DescriptionAttribute)), DescriptionAttribute)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; If da IsNot Nothing Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add(da.Description, enumValue)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;Next &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39; Bind the combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.DataSource = New BindingSource(CustomerTypeList, _       &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Nothing) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This code defines a Dictionary to contain the description of the enum and the integer value of the enum. The for/each loop iterates through the set of Enum values. It uses reflection to find the DescriptionAttribute. It then adds the description and value to the dictionary. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="ver"&gt;The code then binds to the ComboBox, setting the DisplayMember to the “Key” of the dictionary and the ValueMember to the “Value” of the Dictionary.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="ver"&gt;&lt;font color="#65402e"&gt;Now the combo&lt;/font&gt; box looks like this:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3568.image_5F00_2B1A5629.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7360.image_5F00_thumb_5F00_1F8498EA.png" width="234" height="94" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Much better!&lt;/p&gt;  &lt;h2&gt;Extension Methods&lt;/h2&gt;  &lt;p&gt;So the user interface looks nicer, but the code to get the DescriptionAttribute looks rather tedious. It would be much nicer if there was a GetDescription method on the Enum. But hey, with the extension method feature introduced in .NET 3.5, we can build one ourselves!&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public static string GetDescription(this Enum currentEnum)      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string description = String.Empty;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DescriptionAttribute da ; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; FieldInfo fi = currentEnum.GetType().      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetField(currentEnum.ToString());       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi,&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;typeof(DescriptionAttribute));      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (da != null)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; description = da.Description;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; else       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; description = currentEnum.ToString(); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; return description;      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;ExtensionAttribute()&amp;gt; _      &lt;br /&gt;Public Function GetDescription(ByVal currentEnum As [Enum]) As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim description As String = String.Empty       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim da As DescriptionAttribute &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Dim fi As FieldInfo = currentEnum.GetType. _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetField(currentEnum.ToString)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; da = DirectCast(Attribute.GetCustomAttribute(fi, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetType(DescriptionAttribute)), DescriptionAttribute)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; If da IsNot Nothing Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; description = da.Description       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Else       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; description = currentEnum.ToString       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Return description      &lt;br /&gt;End Function&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The C# code can reside in any static class. The VB code must reside in a module, which provides the same features as a static class.&lt;/p&gt;  &lt;p&gt;This code uses reflection to get the DescriptionAttribute for any Enum value. So it can be readily reused. The code returns the DescriptionAttribute if one is found, otherwise it returns the name.&lt;/p&gt;  &lt;h2&gt;Binding to an Enum Description - Redux&lt;/h2&gt;  &lt;p&gt;Now the binding code is much easier to work with.&lt;/p&gt;  &lt;p&gt;In C#:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dictionary&amp;lt;string, int&amp;gt; CustomerTypeList =      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new Dictionary&amp;lt;string, int&amp;gt;(); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;foreach (Customer.CustomerTypeOption enumValue in      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Enum.GetValues(typeof(Customer.CustomerTypeOption)))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add(enumValue.GetDescription(), (int)enumValue);       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;// Bind the customer type combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;;       &lt;br /&gt;CustomerTypeComboBox.DataSource = new BindingSource(CustomerTypeList,&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; null);&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In VB:&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Dim CustomerTypeList As New Dictionary(Of String, Integer)      &lt;br /&gt;      &lt;br /&gt;For Each enumValue As Customer.CustomerTypeOption In _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Enum].GetValues(GetType(Customer.CustomerTypeOption))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; CustomerTypeList.Add(enumValue.GetDescription, enumValue)       &lt;br /&gt;Next &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39; Bind the combo box      &lt;br /&gt;CustomerTypeComboBox.DisplayMember = &amp;quot;Key&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.ValueMember = &amp;quot;Value&amp;quot;       &lt;br /&gt;CustomerTypeComboBox.DataSource = New BindingSource(CustomerTypeList, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Nothing)&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1699394" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Enum/default.aspx">Enum</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Binding/default.aspx">Binding</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Extension+Method/default.aspx">Extension Method</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/WinForms/default.aspx">WinForms</category></item></channel></rss>