unknown
3/22/2009 7:02:00 PM
you can do it in the constructor, or if thats too early, do it in the
get/set methods.
bool myPropInited = false;
string myProp
{
get
{
if (!myPropInited)
{
setDefaultValue();
myPropInited = true;
}
return myPropvalue;
}
set
{
myPropInited = true;
.....
}
}
-- bruce (sqlwork.com)
Nathan Sokalski wrote:
> I need to specify the default value for a property of a custom control I am
> making. Normally this would be done as follows:
>
> Private _myprop As String = "My Default Value"
>
> <System.ComponentModel.DefaultValue("My Default Value")> Public Property
> MyProperty() As String
> Get
> Return Me._myprop
> End Get
> Set(ByVal value As String)
> Me._myprop = value
> End Set
> End Property
>
>
> However, in my situation I am not using a private variable to store the
> value. If I understand correctly, the Property -> Sets for any properties
> specified is the first thing to occur in the control. Is there a way to
> specify a default value without using the technique I show above? Thanks.