473,671 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(T estValues.Value 1)_
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(G etType(TestValu es), "Value1")_

But that doesn't work either....

What am I missing?

/Johnny J.
Feb 6 '08 #1
3 8437
On Feb 6, 6:22 am, "Johnny Jörgensen" <j...@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(T estValues.Value 1)_
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(G etType(TestValu es), "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.Valu e1)_
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(TestVal ues), "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(T estValues.Value 1)) does not work in VS2005
VB.
Feb 6 '08 #3
Thanks.

<DefaultValue(G etType(TestValu es), "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******@cinno vations.netskre v i meddelandet
news:u8******** *************** *********@4ax.c om...
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.Val ue1)_
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(TestVa lues), "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(T estValues.Value 1)) 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
11448
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 ignores it! I´ve also tried other things like:
2
3949
by: tinyabs | last post by:
Hi, How do it set the default value of PopupSize? public Size PopupSize {
6
1910
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? Regards; Meelis
2
1301
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"), _ DefaultValue("myDefaultValue")> _ Public Property MyProperty() As String Get
0
1394
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 Bold in the Property Editor and attempting to Reset the Property fails with an error (see below.) Steps to recreate this issue... Create a UserControl with the following code:
4
5351
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 property will not serialilze to an XML file. If the attribute is removed the serialization occurs just fine. Is there a way around this bug? This behavior seems to work with any type of property. --
6
9381
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") DefaultValue("bool","true")
5
5829
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; } set { myBool = value; } } ======================
1
1136
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 as Color <DefaultValue(GetType(Color), "1, 2, 3")_
0
8474
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.