473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Property DefaultValue

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
Mar 20 '06 #1
6 1900
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.

Mar 20 '06 #2
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

"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.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.

Mar 20 '06 #3
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.

Mar 20 '06 #4
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" <me***********@deltmar.ee> escribió en el mensaje news:e9**************@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

Mar 20 '06 #5
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$**************@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" <me***********@deltmar.ee> escribió en el mensaje
news:e9**************@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
Mar 20 '06 #6
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" <me***********@deltmar.ee> escribió en el mensaje news:e$**************@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$**************@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" <me***********@deltmar.ee> escribió en el mensaje
| news:e9**************@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

Mar 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: timtos | last post by:
I want to set a color property of a user control by default. I am doing it like this: .... DefaultValue(typeof(System.Drawing.Color), "Blue"), .... The compiler likes it but my program...
0
by: Joe | last post by:
I wrote a simple server control that inherits from the DropDownList control. I will be using the control in an aspx page and want to access it in a repeater. I have created a public property...
0
by: Joe | last post by:
I am having a hard time with setting a property on a custom server control that i am placing in a repeater. The control inherits from DropDownList. The property is being set in the repeater using...
2
by: Lance | last post by:
I want to be able to reset a complex property in a PropertyGrid. I know that for properties that are ValueTypes you can include System.ComponentModel.DefaultValue in the declaration of the property....
27
by: Just Me | last post by:
I made a Usercontrol that must have AutoScroll set to true when it is used. So I set it to True in the Load event. However the property still shows in the properties window when the control is...
0
by: Shadow Lynx | last post by:
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...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
9
by: Eric | last post by:
Hi Everyone, I'm writing a UserControl that exposes a property of the type System.Drawing.Image, like this: Public Property DefaultImage() As Image Get Return propDefaultImage End Get...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.