473,394 Members | 1,699 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,394 software developers and data experts.

DefaultValue attribute for a property with an enum type

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

<DefaultValue(TestValues.Value1)_
Public Property TestValue() As TestValues
'Get and set here
End Property

The above doesn't work. When the property has the defaultvalue, it is still
not considered default.

I also tried

<DefaultValue(GetType(TestValues), "Value1")_

But that doesn't work either....

What am I missing?

/Johnny J.
Feb 6 '08 #1
3 8413
On Feb 6, 6:22 am, "Johnny Jörgensen" <j...@altcom.sewrote:
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

<DefaultValue(TestValues.Value1)_
Public Property TestValue() As TestValues
'Get and set here
End Property

The above doesn't work. When the property has the defaultvalue, it is still
not considered default.

I also tried

<DefaultValue(GetType(TestValues), "Value1")_

But that doesn't work either....

What am I missing?

/Johnny J.
Can you just store the integer value of the enum? i.e use 1 for Value1
or 2 for Value2?

Thanks,

Seth Rowe [MVP]
Feb 6 '08 #2
On Wed, 6 Feb 2008 12:22:27 +0100, "Johnny Jörgensen" <jo**@altcom.se>
wrote:
>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

<DefaultValue(TestValues.Value1)_
Public Property TestValue() As TestValues
'Get and set here
End Property

The above doesn't work. When the property has the defaultvalue, it is still
not considered default.

I also tried

<DefaultValue(GetType(TestValues), "Value1")_

But that doesn't work either....

What am I missing?
I don't know. The second form works for me. I have read that the
first form (DefaultValue(TestValues.Value1)) does not work in VS2005
VB.
Feb 6 '08 #3
Thanks.

<DefaultValue(GetType(TestValues), "Value1")_

is actually working now. I wasn't when I posted this before. Strange, but
not unusual for VS.

Cheers,
Johnny J.
"Jack Jackson" <jj******@cinnovations.netskrev i meddelandet
news:u8********************************@4ax.com...
On Wed, 6 Feb 2008 12:22:27 +0100, "Johnny Jörgensen" <jo**@altcom.se>
wrote:
>>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

<DefaultValue(TestValues.Value1)_
Public Property TestValue() As TestValues
'Get and set here
End Property

The above doesn't work. When the property has the defaultvalue, it is
still
not considered default.

I also tried

<DefaultValue(GetType(TestValues), "Value1")_

But that doesn't work either....

What am I missing?

I don't know. The second form works for me. I have read that the
first form (DefaultValue(TestValues.Value1)) does not work in VS2005
VB.

Feb 7 '08 #4

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...
2
by: tinyabs | last post by:
Hi, How do it set the default value of PopupSize? public Size PopupSize {
6
by: Meelis Lilbok | last post by:
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? ...
2
by: job | last post by:
I'm having trouble getting the DefaultValue property attribute on my server control show up in design time. Here my property code: <Bindable(True), _ Category("Misc"), _...
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...
4
by: SteveT | last post by:
I have a boolean property that I want to serialize to disk using XmlSerializer. I noticed that if the property includes the attribute "DefaultValue(true)" or "DefaultValue(false)" that the...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Prior to C# 3.0, I would typically define a property of a custom user control with pattern A: === PATTERN A ========== private bool myBool = true; public bool MyBool { get { return myBool; }...
1
by: Olaf Rabbachin | last post by:
Hi folks, I'd like to retrieve default values for properties (of a user control) via code instead of having string-constants. Consider the following (simplified) property: Private _MyColor...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.