Property DefaultValue

M

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
 
C

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

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
 
C

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

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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" <[email protected]> escribió en el mensaje | 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
 
M

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
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" <[email protected]> escribió en el mensaje
| 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
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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.


"Meelis Lilbok" <[email protected]> escribió en el mensaje | 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
| | 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" <[email protected]> escribió en el mensaje
| || 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top