﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » Enum data type</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Wed, 10 Jun 2026 20:36:13 GMT</lastBuildDate><ttl>20</ttl><item><title>Enum data type</title><link>http://forum.strataframe.net/FindPost5670.aspx</link><description>Hi,&lt;br&gt;
May I know what is the data type used by enum? I have a combobox that use enum as population. It hits error if I bind it to a integer field.&lt;br&gt;
&lt;br&gt;
[quote]System.InvalidCastException was unhandled by user code&lt;br&gt;
  Message="Specified cast is not valid."&lt;br&gt;
  Source="InventoryBusinessObject"&lt;br&gt;
  StackTrace:&lt;br&gt;
       at JK.Inventory.BusinessObject.CompanyAddressBO.get_AddressTypeID() in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 321&lt;br&gt;
       at JK.Inventory.BusinessObject.CompanyAddressBO.Field_AddressTypeID_Descriptor.GetValue(Object component) in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 751&lt;br&gt;
       at System.Windows.Forms.BindToObject.GetValue()&lt;br&gt;
       at System.Windows.Forms.Binding.PushData(Boolean force)&lt;br&gt;
[/quote]</description><pubDate>Thu, 11 Jan 2007 11:55:36 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5750.aspx</link><description>[quote]&lt;SPAN id=_ctl1__ctl0_ctlTopic__ctl0_ctlPanelBar_ctlTopicsRepeater__ctl1_lblFullMessage&gt;Hi,&lt;BR&gt;My enum do have 0 value&lt;BR&gt;&lt;BR&gt;public enum myEnum {Billing, Corresponding, Home};[/quote]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not sure then... I'd have to see it at runtime and test several things within the Watch &amp;#119;indow.&amp;nbsp; I'm glad you got it working, though, with your explicit default value.&lt;/SPAN&gt;</description><pubDate>Thu, 11 Jan 2007 11:55:36 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5734.aspx</link><description>Hi,&lt;br&gt;
My enum do have 0 value&lt;br&gt;
&lt;br&gt;
public enum myEnum {Billing, Corresponding, Home};</description><pubDate>Thu, 11 Jan 2007 00:47:36 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5726.aspx</link><description>When you add a new record, SF initializes all of the fields within the record so that there are no DBNull.Value fields.&amp;nbsp; This functionality can be turned off on the business object by setting the AllowNullValuesOnNewRow property to True on the business object.&amp;nbsp; Most likely, your enum did not have a value for 0, which is what the integer fields are initialized to.&amp;nbsp; So, but, explicitly setting the value for the field within SetDefaultValues() will always work.</description><pubDate>Wed, 10 Jan 2007 14:11:40 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5718.aspx</link><description>Hi,&lt;br&gt;
Sorry, one more question here. I found that only integer field shown as {} but string is "" when add new record. Is it .NET "feature" or ...?&lt;br&gt;
&lt;br&gt;
Thank you</description><pubDate>Wed, 10 Jan 2007 10:35:40 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5717.aspx</link><description>Hi,&lt;br&gt;
Sorry to trouble you again.&lt;br&gt;
After some debugging, when I call myBO.Add(), VS.NET shown my field value as {} which I guest is NULL. Therefore, .NET complaint when read the property which also cast field value to enum data type. &lt;br&gt;
&lt;br&gt;
I got set value to "NULL Replacement Value" under business object mapper but it doesn't seem to work. Any ideas?&lt;br&gt;
&lt;br&gt;
At last, what I did is explicit set default value to myField in myBO_SetDefaultValues event and it solves the problem.&lt;br&gt;
&lt;br&gt;
Please advice.&lt;br&gt;
&lt;br&gt;
Thank you&lt;br&gt;</description><pubDate>Wed, 10 Jan 2007 10:27:50 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5699.aspx</link><description>Hi,&lt;br&gt;
I moved enum to enumeration.cs and try again.. still the same.&lt;br&gt;
FYI, I typed the code below in editor and VS.NET able to show me the enum list. But when I search enum from BO mapper custom data type search, it doesn't list anything. It just return what I type back to the column.&lt;br&gt;
&lt;br&gt;
this.companyaddressbo.addresstypeID = &lt;br&gt;
&lt;br&gt;
Really strange&lt;br&gt;
&lt;br&gt;
BTW, my field is INT field type. Any impact?&lt;br&gt;
&lt;br&gt;</description><pubDate>Tue, 09 Jan 2007 11:49:30 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5698.aspx</link><description>Do you have the enum defined in 2 different locations?&amp;nbsp; Within both the CompanyAddressBO.cs and the CompanyAddressBO.designer.cs files?&amp;nbsp; It is strange that the compiler would let you compile it with the same type defined in 2 different locations.&amp;nbsp; Try deleting one of them and running it again... most likely, the combo box is being populated from one of them while the business object is casting it's enum as the other type causing your cast exception.</description><pubDate>Tue, 09 Jan 2007 11:28:15 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5696.aspx</link><description>Hi,&lt;br&gt;
Thank you for reply.&lt;br&gt;
However, I still unable to make it.&lt;br&gt;
&lt;br&gt;
I declared enum, able to populate combobox by refer to enum, set it as custom data field type in BO mapper (able to search from data type browse dialog). However, when I click new button, I still hit error.&lt;br&gt;
&lt;br&gt;
[codesnippet]CompanyAddressBO.cs&lt;br&gt;
namespace JK.Inventory.BusinessObject&lt;br&gt;
{&lt;br&gt;
    public enum AddressType { Corresponding, Shipping, Billing };&lt;br&gt;
&lt;br&gt;
    [Serializable()]&lt;br&gt;
    public partial class CompanyAddressBO : MicroFour.StrataFrame.Business.BusinessLayer&lt;br&gt;
    {&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
CompanyAddressBO.designer.cs&lt;br&gt;
&lt;br&gt;
namespace JK.Inventory.BusinessObject&lt;br&gt;
{&lt;br&gt;
    public enum AddressType { Corresponding, Shipping, Billing };&lt;br&gt;
&lt;br&gt;
    [Serializable()]&lt;br&gt;
    public partial class CompanyAddressBO : MicroFour.StrataFrame.Business.BusinessLayer&lt;br&gt;
    {&lt;br&gt;
&lt;br&gt;
       [Browsable(false),&lt;br&gt;
         BusinessFieldDisplayInEditor(),&lt;br&gt;
         Description("This field was imported."),&lt;br&gt;
         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]&lt;br&gt;
        public JK.Inventory.BusinessObject.AddressType AddressTypeID&lt;br&gt;
        {&lt;br&gt;
            get&lt;br&gt;
            {&lt;br&gt;
                // ERROR HERE!!!!!!&lt;br&gt;
                return (JK.Inventory.BusinessObject.AddressType)this.CurrentRow["AddressTypeID"];&lt;br&gt;
            }&lt;br&gt;
            set&lt;br&gt;
            {&lt;br&gt;
                this.CurrentRow["AddressTypeID"] = value;&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
   }&lt;br&gt;
}&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
Error:&lt;br&gt;
System.InvalidCastException was unhandled by user code&lt;br&gt;
  Message="Specified cast is not valid."&lt;br&gt;
  Source="InventoryBusinessObject"&lt;br&gt;
  StackTrace:&lt;br&gt;
       at JK.Inventory.BusinessObject.CompanyAddressBO.get_AddressTypeID() in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 321&lt;br&gt;
       at JK.Inventory.BusinessObject.CompanyAddressBO.Field_AddressTypeID_Descriptor.GetValue(Object component) in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 751&lt;br&gt;
       at System.Windows.Forms.BindToObject.GetValue()&lt;br&gt;
       at System.Windows.Forms.Binding.PushData(Boolean force)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thank you</description><pubDate>Tue, 09 Jan 2007 10:55:29 GMT</pubDate><dc:creator>kkchan</dc:creator></item><item><title>RE: Enum data type</title><link>http://forum.strataframe.net/FindPost5675.aspx</link><description>When you populate a combo box from an enum, you have to bind the combo box to a field that is typed as the same enum (through the field customization in the business object mapper).&amp;nbsp; When the combo box is populated, it does not use an integer type as the value for each item within the combo box, but rather the actual enum value.&amp;nbsp; So, you have to bind to a field that uses that same enum value or the data-types do not match.</description><pubDate>Mon, 08 Jan 2007 10:23:02 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>