When I set the "type" of a numeric editor to decimal, start the application, dont change anything (ie accept the default 0 ("zero"))
and then call:
(decimal) numericEditor.Value
I get an exception. Why is that? When I manually type in 0, the Value parameter is castable to decimal. The default, unchanged zero seems to be an integer....
Am I doing something wrong?
What's the error?
My best guess is that the Value is null at that point, and the control simply displays a 0 for null. The solution would be to simply check for null before trying to cast the Value to a decimal.
It looks like a bug to me. When I set the value to 0 in the property editor on the form designer, the type of value seems to be a boxed (int), when I set it to 0 programmatically or via user input it is a boxed decimal (as expected).
The exception is an InvalidCast.