472,783 Members | 938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

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 9337
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe Bloggs | last post by:
Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1...
2
by: Jon Turner | last post by:
When developing a custom control, lets say I have a property named "WidgetType" and this property can consist of 3 types "WidgetStandard, WidgetEnhanced, WidgetSimple". How does my control notify...
0
by: Steve R | last post by:
I've built a composite web custom control with a lot of child controls. I assigned ToolTip values to some of these controls. The ToolTip pop-ups were working fine until I monkeyed with the order...
2
by: Earl Teigrob | last post by:
I have a custom control that creates a textarea child control and diplays it to the user. The control is defined as follows System.Web.UI.HtmlControls.HtmlTextArea TextArea1; I have a property...
1
by: Sanjay Pais | last post by:
I built a custom control for all the basic web.ui.controls like textbox, label, checkbox etc etc. I added my custom attribute called ApplySecurity to the html in the page. However, when I cycle...
0
by: dan | last post by:
Hi NG, i am developing an asp.net Custom control which consist of some TextBoxes, Button, ... . To let the user of that control set for example the width of the TextBox, the class has a...
0
by: Kay | last post by:
Hello, I have developed a web custom control, I want one of the properties of the control to appear as a dropdown list so the user can select from the list. My question is: how do I define an...
0
by: Kay | last post by:
Hello, I have developed a web custom control, I want one of the properties of the control to appear as a dropdown list so the user can select from the list. My question is: how do I define an...
2
by: Nathan Sokalski | last post by:
I have a custom control with properties named MinValue, MaxValue, and Value (all of which I have assigned a DefaultValue design-time attribute). The Value property must be between (or equal to) the...
1
by: --== Alain ==-- | last post by:
Hi, I still have problem updating my custom control at design time. When i change a property of my custom control in the property window, i would like to see this change immediately on my custom...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.