473,511 Members | 10,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting defaultvalue of a property

RR
Hi,

I want to set the defaultvalue of a property in a class.

I know this is possible by the DefaultValue Attribute like this:

public class Test
{
public Test(){}

private string myProperty;

[DefaultValue("TestProperty")]
public string MyProperty
{
get{ return myProperty; }
set{ myProperty = value; }
}
}

I search for a possibility to set the default value for several
languages.

(the defaultvalueattribute class is sealed!!).

How can I implement this functionality??

Nov 17 '05 #1
1 1469
"RR" <ro************@freenet.de> wrote in
news:11*********************@f14g2000cwb.googlegro ups.com:
Hi,

I want to set the defaultvalue of a property in a class.

I know this is possible by the DefaultValue Attribute like this:

public class Test
{
public Test(){}

private string myProperty;

[DefaultValue("TestProperty")]
public string MyProperty
{
get{ return myProperty; }
set{ myProperty = value; }
}
}

I search for a possibility to set the default value for several
languages.

(the defaultvalueattribute class is sealed!!).

How can I implement this functionality??


Robert,

Is this what you mean by "possibility to set the default value for
several languages"?

using System.Globalization;

....

private string myProperty = null;
public string MyProperty
{
get
{
// If myProperty has already been set to a value,
// return that value.
if (myProperty != null)
return myProperty;

// Otherwise, return a language-specific default value.
if (CultureInfo.CurrentUICulture.Name == "de-DE")
return "German text";
else if (CultureInfo.CurrentUICulture.Name == "en-EN")
return "English text";
else if (CultureInfo.CurrentUICulture.Name == "jp-JP")
return "Japanese text";
else
return "German text";
}

set { myProperty = value; }
}
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2

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

Similar topics

1
1949
by: Mark | last post by:
How do I write the following code to set the default value? Me!xNum.DefaultValue = Me!XCurrency.DefaultValue = Me!XDate.DefaultValue = Me!XString.DefaultValue = Can I just put all the lines...
10
2719
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
18
18309
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
2
11423
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...
7
20751
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
1
1040
by: Cesar Ronchese | last post by:
Hi all. I need to set a default value to my UserControl, but I'm getting a error when trying reset the value via PropertyGrid on the host IDE: "Object type cannot be converted to target type". ...
6
2500
by: MLH | last post by:
I have a form named frmVehicleEntryForm. It has a 3-tab tab control. On the 2nd tab page, there's a textbox named VehicleLocationName whose default value setting is ...
5
8316
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I have the following AccessDataSource control on my page.. <asp:AccessDataSource ID="adsAllStories" runat="server" DataFile="~/App_Data/Stories.mdb" SelectCommand="SELECT StoryID,...
3
8424
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
7251
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
7148
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
7367
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
7430
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...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.