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 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.
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.
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.
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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,...
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |