470,591 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

DefaultValue of Custom control

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")

For a max value of a property of type _long_ (although max value is set to
max of int32)
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

For a custom enum:
DefaultValue(TextBoxNumericType.WholeNumber)
DefaultValue("TextBoxNumericType.WholeNumber")
DefaultValue("TextBoxNumericType", "TextBoxNumericType.WholeNumber")

I'm not successfull in any of the cases above...

Thanks in advance!

/ Peter
Oct 12 '06 #1
6 9213
Should be one of these (for a bool):

VB <DefaultValue(False)>
C# [DefaultValue(false)]

Have you tired setting the attribute directly in the code rather than
using the dialog window?

More info here:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

Peter Hartlén wrote:
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")

For a max value of a property of type _long_ (although max value is set to
max of int32)
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

For a custom enum:
DefaultValue(TextBoxNumericType.WholeNumber)
DefaultValue("TextBoxNumericType.WholeNumber")
DefaultValue("TextBoxNumericType", "TextBoxNumericType.WholeNumber")

I'm not successfull in any of the cases above...

Thanks in advance!

/ Peter
Oct 12 '06 #2
What I actually wonder is how I get the designer not to write the default
value into IntializeComponent, which is the main usage of DefaultValue
property.
For a max value of a property of type _long_ (although max value is set to
max of int32)
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")
For this property I have the following declaration:
long m_lMaxVal = Int32.MaxValue;
public long MaxValue

{

get{ return m_lMaxVal;}

set

{

if( value >= MinValue )

{

m_lMaxVal = value;

}
}
}

But the value is written to InitializeComponent anyway:

this.textBoxNumeric2.MaxValue = ((long)(2147483647));
Oct 12 '06 #3
Hi Chris, thanks for replying!

Yes, please read my second post, I do set the default value for the
underlying member in the class. So the _value_ of the property is set
correctly in the designer. BUT, if this value is the same as the
DefaultValue value, the designer shouldn't write it into the
InitializeComponent method, which always happens for me..

Any ideas on this?

/ Peter
"Chris Fulstow" <ch**********@hotmail.comskrev i meddelandet
news:11*********************@e3g2000cwe.googlegrou ps.com...
Should be one of these (for a bool):

VB <DefaultValue(False)>
C# [DefaultValue(false)]

Have you tired setting the attribute directly in the code rather than
using the dialog window?

More info here:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx

Peter Hartlén wrote:
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")

For a max value of a property of type _long_ (although max value is set to
max of int32)
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

For a custom enum:
DefaultValue(TextBoxNumericType.WholeNumber)
DefaultValue("TextBoxNumericType.WholeNumber")
DefaultValue("TextBoxNumericType", "TextBoxNumericType.WholeNumber")

I'm not successfull in any of the cases above...

Thanks in advance!

/ Peter

Oct 12 '06 #4
Peter Hartlén wrote:
Hi Chris, thanks for replying!

Yes, please read my second post, I do set the default value for the
underlying member in the class. So the _value_ of the property is set
correctly in the designer. BUT, if this value is the same as the
DefaultValue value, the designer shouldn't write it into the
InitializeComponent method, which always happens for me..

Any ideas on this?

/ Peter
"Chris Fulstow" <ch**********@hotmail.comskrev i meddelandet
news:11*********************@e3g2000cwe.googlegrou ps.com...
Should be one of these (for a bool):

VB <DefaultValue(False)>
C# [DefaultValue(false)]

Have you tired setting the attribute directly in the code rather than
using the dialog window?

More info here:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx
>
Peter Hartlén wrote:
>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")

For a max value of a property of type _long_ (although max value is set
to max of int32)
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

For a custom enum:
DefaultValue(TextBoxNumericType.WholeNumber)
DefaultValue("TextBoxNumericType.WholeNumber")
DefaultValue("TextBoxNumericType", "TextBoxNumericType.WholeNumber")

I'm not successfull in any of the cases above...

Thanks in advance!

/ Peter
Hi Peter,

Actually, it probably should. All you're doing by applying a DefaultValue
attribute to a property is, well, apply an attribute to a property. The
property *still* needs to be initialised with a value, and it gets
initialised to the value automatically that you've provided via the
DefaultValue attribute.

The attribute in no way causes the framework to start assigning values to
variable, without an *actual* assignment statement... that would be crazy
talk!

--
Hope this helps,
Tom Spink

Google first, ask later.
Oct 12 '06 #5
"Tom Spink" <ts****@gmail.comskrev i meddelandet
news:eZ**************@TK2MSFTNGP02.phx.gbl...
Hi Peter,

Actually, it probably should. All you're doing by applying a DefaultValue
attribute to a property is, well, apply an attribute to a property. The
property *still* needs to be initialised with a value, and it gets
initialised to the value automatically that you've provided via the
DefaultValue attribute.

The attribute in no way causes the framework to start assigning values to
variable, without an *actual* assignment statement... that would be crazy
talk!
I'm not sure I understand what you mean here, but I think we are saying the
same thing :-)

I never stated that the DefaultValue attribute initalizes my variables!

This is what I do:
long m_lMaxVal = Int32.MaxValue;
public long MaxValue
{
get{ return m_lMaxVal;}
set{if( value >= MinValue ){m_lMaxVal = value;}}
}

and then I use any of this in the __ClassDiagram Custom Attribute dialog__
(I'm not setting the attributes in the code):
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

(the same thing applies for a simple property/variable of type bool)
bool m_bTest = false;
public bool ATest
{
get{return m_bTest;}
set{m_bTest=value;}
}

DefaultValue(true)

** THIS IS THE PROBLEM **
But the value is written to InitializeComponent anyway:
this.textBoxNumeric2.MaxValue = ((long)(2147483647));

This is an extract from msdn docs (the link given previously in this post):
"Code generators can use the default values also to determine whether code
should be generated for the member."

So atleast one of the ideas with the DefaultValue attribute is to prevent
code beeing generated in the InitalizeComponent function.

The confusing part here is what arguments the DefaultValue attribute takes,
as it seems it is able to take one or two arguments. This is not documented
as far as I know, or I have not been looking in the right place.
Oct 13 '06 #6
Peter Hartlén wrote:
"Tom Spink" <ts****@gmail.comskrev i meddelandet
news:eZ**************@TK2MSFTNGP02.phx.gbl...
>Hi Peter,

Actually, it probably should. All you're doing by applying a
DefaultValue
attribute to a property is, well, apply an attribute to a property. The
property *still* needs to be initialised with a value, and it gets
initialised to the value automatically that you've provided via the
DefaultValue attribute.

The attribute in no way causes the framework to start assigning values to
variable, without an *actual* assignment statement... that would be crazy
talk!

I'm not sure I understand what you mean here, but I think we are saying
the same thing :-)

I never stated that the DefaultValue attribute initalizes my variables!

This is what I do:
long m_lMaxVal = Int32.MaxValue;
public long MaxValue
{
get{ return m_lMaxVal;}
set{if( value >= MinValue ){m_lMaxVal = value;}}
}

and then I use any of this in the __ClassDiagram Custom Attribute dialog__
(I'm not setting the attributes in the code):
DefaultValue(Int32.MaxValue)
DefaultValue("Int32.MaxValue")
DefaultValue("long", "Int32.MaxValue")
DefaultValue("int", "Int32.MaxValue")

(the same thing applies for a simple property/variable of type bool)
bool m_bTest = false;
public bool ATest
{
get{return m_bTest;}
set{m_bTest=value;}
}

DefaultValue(true)

** THIS IS THE PROBLEM **
But the value is written to InitializeComponent anyway:
this.textBoxNumeric2.MaxValue = ((long)(2147483647));

This is an extract from msdn docs (the link given previously in this
post): "Code generators can use the default values also to determine
whether code should be generated for the member."

So atleast one of the ideas with the DefaultValue attribute is to prevent
code beeing generated in the InitalizeComponent function.

The confusing part here is what arguments the DefaultValue attribute
takes, as it seems it is able to take one or two arguments. This is not
documented as far as I know, or I have not been looking in the right
place.
Hi,

If you think about that statement the other way round, it could mean that
code generators know that they MUST write code for that member.

The DefaultValue attribute will _cause_ the generation of code for that
member because your code doesn't necessarily set up the default value to be
what you've said it is.

Does this make things clearer?

--
Hope this helps,
Tom Spink

Google first, ask later.
Oct 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jon Turner | last post: by
1 post views Thread by Sanjay Pais | last post: by
1 post views Thread by --== Alain ==-- | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.