Home All Groups Group Topic Archive Search About

Property DefaultValue

Author
20 Mar 2006 8:22 AM
Meelis Lilbok
Hi

Why does property default value not work?
When i start my application and dont set value from properties window
the value is always "nothing". Whats the point off DefualtValue then?

Regards;
Meelis


Private const cSaveText as string = "Save"
Private const cButtons as string = "Buttons"

<Description("Save button text"), Category(cButtons),
DefaultValue(cSaveText)> _
Public Property SaveButtonText() As String
Get
    Return MySaveButtonText
End Get
Set(ByVal value As String)
    MySaveButtonText = value
    cmbSave.Text = value
End Set
End Property

Author
20 Mar 2006 9:19 AM
Cerebrus
Hi,

You need to initialize the variable "MySaveButtonText" as well, since
that is what you are *returning* in the Getter. For string variables, I
believe this is necessary.

Try adding the following line along with the Constant declarations :
---------------------------------------------------------
Private mySaveButtonText As String = cSaveText
---------------------------------------------------------

Hope this helps,

Regards,

Cerebrus.
Author
20 Mar 2006 9:42 AM
Meelis Lilbok
HI

Yes i allready have this (Private mySaveButtonText As String = cSaveText)
but this does not help.
If propertyvalue is not specified from property window, value is still
nothing.


Meelis



Show quoteHide quote
"Cerebrus" <zorg***@sify.com> wrote in message
news:1142846357.473724.170650@t31g2000cwb.googlegroups.com...
> Hi,
>
> You need to initialize the variable "MySaveButtonText" as well, since
> that is what you are *returning* in the Getter. For string variables, I
> believe this is necessary.
>
> Try adding the following line along with the Constant declarations :
> ---------------------------------------------------------
> Private mySaveButtonText As String = cSaveText
> ---------------------------------------------------------
>
> Hope this helps,
>
> Regards,
>
> Cerebrus.
>
Author
20 Mar 2006 11:50 AM
Cerebrus
That *is* surprising, since it worked for me, when I copied and pasted
your code. Are you sure, the value is not getting changed elsewhere ?

Regards,

Cerebrus.
Author
20 Mar 2006 11:56 AM
José_Manuel_Agüero
Hello Meelis,

You should set the initial values in the constructor of your class.
The DefaultValue attribute is used by Visual Studio in the properties window: When you right click the property you will see a Reset item in the menu. It will reset the value to the one assigned in the DefaultValue attribute.

Regards.


Show quoteHide quote
"Meelis Lilbok" <meelis.lil***@deltmar.ee> escribió en el mensaje news:e9v0Ud$SGHA.5108@TK2MSFTNGP09.phx.gbl...
| Hi
|
| Why does property default value not work?
| When i start my application and dont set value from properties window
| the value is always "nothing". Whats the point off DefualtValue then?
|
| Regards;
| Meelis
|
|
| Private const cSaveText as string = "Save"
| Private const cButtons as string = "Buttons"
|
| <Description("Save button text"), Category(cButtons),
| DefaultValue(cSaveText)> _
| Public Property SaveButtonText() As String
| Get
|    Return MySaveButtonText
| End Get
| Set(ByVal value As String)
|    MySaveButtonText = value
|    cmbSave.Text = value
| End Set
| End Property
Author
20 Mar 2006 12:10 PM
Meelis Lilbok
Hi and thnx José

But what when i want to change property in design mode and when no value is
entered for property
then defualtvalue is omitted automatically?


Regards;
Meelis




"José Manuel Agüero" <chema012 en hotmail.com> wrote in message
news:u$vKiVBTGHA.5656@TK2MSFTNGP11.phx.gbl...
Hello Meelis,

You should set the initial values in the constructor of your class.
The DefaultValue attribute is used by Visual Studio in the properties
window: When you right click the property you will see a Reset item in the
menu. It will reset the value to the one assigned in the DefaultValue
attribute.

Regards.


Show quoteHide quote
"Meelis Lilbok" <meelis.lil***@deltmar.ee> escribió en el mensaje
news:e9v0Ud$SGHA.5108@TK2MSFTNGP09.phx.gbl...
| Hi
|
| Why does property default value not work?
| When i start my application and dont set value from properties window
| the value is always "nothing". Whats the point off DefualtValue then?
|
| Regards;
| Meelis
|
|
| Private const cSaveText as string = "Save"
| Private const cButtons as string = "Buttons"
|
| <Description("Save button text"), Category(cButtons),
| DefaultValue(cSaveText)> _
| Public Property SaveButtonText() As String
| Get
|    Return MySaveButtonText
| End Get
| Set(ByVal value As String)
|    MySaveButtonText = value
|    cmbSave.Text = value
| End Set
| End Property
Author
20 Mar 2006 8:12 PM
José_Manuel_Agüero
You can validate the input in the property set method of your component. It can ignore the wrong (or empty) value or throw an exception. In the latter case Visual Studio will show a message saying that the property value was invalid.

Regards.


Show quoteHide quote
"Meelis Lilbok" <meelis.lil***@deltmar.ee> escribió en el mensaje news:e$PQycBTGHA.4608@tk2msftngp13.phx.gbl...
| Hi and thnx José
|
| But what when i want to change property in design mode and when no value is
| entered for property
| then defualtvalue is omitted automatically?
|
|
| Regards;
| Meelis
|
|
|
|
| "José Manuel Agüero" <chema012 en hotmail.com> wrote in message
| news:u$vKiVBTGHA.5656@TK2MSFTNGP11.phx.gbl...
| Hello Meelis,
|
| You should set the initial values in the constructor of your class.
| The DefaultValue attribute is used by Visual Studio in the properties
| window: When you right click the property you will see a Reset item in the
| menu. It will reset the value to the one assigned in the DefaultValue
| attribute.
|
| Regards.
|
|
| "Meelis Lilbok" <meelis.lil***@deltmar.ee> escribió en el mensaje
| news:e9v0Ud$SGHA.5108@TK2MSFTNGP09.phx.gbl...
|| Hi
||
|| Why does property default value not work?
|| When i start my application and dont set value from properties window
|| the value is always "nothing". Whats the point off DefualtValue then?
||
|| Regards;
|| Meelis
||
||
|| Private const cSaveText as string = "Save"
|| Private const cButtons as string = "Buttons"
||
|| <Description("Save button text"), Category(cButtons),
|| DefaultValue(cSaveText)> _
|| Public Property SaveButtonText() As String
|| Get
||    Return MySaveButtonText
|| End Get
|| Set(ByVal value As String)
||    MySaveButtonText = value
||    cmbSave.Text = value
|| End Set
|| End Property