Language: VB.Net 2.0 (Windows Application)
IDE: MS VB 2005 Exp. Ed.
Summary: Setting a DefaultValue of type Decimal for the Property of a
UserControl does not work properly - the value appears Bold in the
Property Editor and attempting to Reset the Property fails with an
error (see below.)
Steps to recreate this issue...
Create a UserControl with the following code:
-----
Imports System.ComponentModel
Public Class TestControl
Private _Test As Decimal = 0D
<DefaultValue(0D)> _
Public Property Test() As Decimal
Get
Return _Test
End Get
Set(ByVal value As Decimal)
_Test = value
End Set
End Property
End Class
-----
Add TestControl to a Windows Form. The "Test" property will become
available in the Properties Editor and is initially set to zero.
I do not understand why the zero appears bold, indicating a non-default
value, since the DefaultValue is specified (as Decimal zero).
If the Test property label is right-clicked and Reset is clicked, the
following error appears:
Object of type 'System.Single' cannot be converted to type
'System.Decimal'
Considering that the DefaultValue is specified as 0D (Decimal zero),
this error should not occur. If I change the DefaultValue to 0
(Integer zero), the error changes to "Object of type 'System.Int32'
...."
Am I doing something incorrectly (or misunderstanding anything) or is
this a bug, and, if I need a Decimal Property with a DefaultValue, how
do I get around this?