Enum data type


Author
Message
kkchan
kkchan
StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)
Group: Forum Members
Posts: 48, Visits: 97
Hi,

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.



System.InvalidCastException was unhandled by user code

Message="Specified cast is not valid."

Source="InventoryBusinessObject"

StackTrace:

at JK.Inventory.BusinessObject.CompanyAddressBO.get_AddressTypeID() in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 321

at JK.Inventory.BusinessObject.CompanyAddressBO.Field_AddressTypeID_Descriptor.GetValue(Object component) in F:\Projects\Inventory\InventoryBusinessObject\CompanyAddressBO.Designer.cs:line 751

at System.Windows.Forms.BindToObject.GetValue()

at System.Windows.Forms.Binding.PushData(Boolean force)


Attachments
enumerror.JPG (153 views, 61.00 KB)
Replies
kkchan
kkchan
StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)
Group: Forum Members
Posts: 48, Visits: 97
Hi,

Sorry to trouble you again.

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.



I got set value to "NULL Replacement Value" under business object mapper but it doesn't seem to work. Any ideas?



At last, what I did is explicit set default value to myField in myBO_SetDefaultValues event and it solves the problem.



Please advice.



Thank you

kkchan
kkchan
StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)
Group: Forum Members
Posts: 48, Visits: 97
Hi,

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 ...?



Thank you
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
When you add a new record, SF initializes all of the fields within the record so that there are no DBNull.Value fields.  This functionality can be turned off on the business object by setting the AllowNullValuesOnNewRow property to True on the business object.  Most likely, your enum did not have a value for 0, which is what the integer fields are initialized to.  So, but, explicitly setting the value for the field within SetDefaultValues() will always work.
kkchan
kkchan
StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)StrataFrame Novice (96 reputation)
Group: Forum Members
Posts: 48, Visits: 97
Hi,

My enum do have 0 value



public enum myEnum {Billing, Corresponding, Home};
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Hi,
My enum do have 0 value

public enum myEnum {Billing, Corresponding, Home};

I'm not sure then... I'd have to see it at runtime and test several things within the Watch window.  I'm glad you got it working, though, with your explicit default value.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
kkchan - 18 Years Ago
StrataFrame Team - 18 Years Ago
kkchan - 18 Years Ago
StrataFrame Team - 18 Years Ago
                     Hi,
I moved enum to enumeration.cs and try again.. still the...
kkchan - 18 Years Ago
                     Hi,
Sorry to trouble you again.
After some debugging, when I...
kkchan - 18 Years Ago
                         Hi,
Sorry, one more question here. I found that only integer...
kkchan - 18 Years Ago
                             When you add a new record, SF initializes all of the fields within the...
StrataFrame Team - 18 Years Ago
                                 Hi,
My enum do have 0 value

public enum myEnum...
kkchan - 18 Years Ago
                                     [quote] Hi, My enum do have 0 value public enum myEnum {Billing,...
StrataFrame Team - 18 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search