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

DefaultValueAttribute Not Working

I've create a custom DataGridColumnStyle and when I try to assign a
DefaultValue to a property, it doesn't seems to have any effect.

Here is the code:

[DefaultValue(10)]
public int Test
{
get{return 0;}
set{}
}

the default value shown is 0 instead.
I also tried [DefaultValue(typeof(int), "10")] with no effect.

Thanks,
Homa Wong

Jul 21 '05 #1
3 1921
Well, your Getter is always returning 0, isn't it?

"Homa" <ho******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I've create a custom DataGridColumnStyle and when I try to assign a
DefaultValue to a property, it doesn't seems to have any effect.

Here is the code:

[DefaultValue(10)]
public int Test
{
get{return 0;}
set{}
}

the default value shown is 0 instead.
I also tried [DefaultValue(typeof(int), "10")] with no effect.

Thanks,
Homa Wong

Jul 21 '05 #2
Well, your Getter is always returning 0, isn't it?

"Homa" <ho******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I've create a custom DataGridColumnStyle and when I try to assign a
DefaultValue to a property, it doesn't seems to have any effect.

Here is the code:

[DefaultValue(10)]
public int Test
{
get{return 0;}
set{}
}

the default value shown is 0 instead.
I also tried [DefaultValue(typeof(int), "10")] with no effect.

Thanks,
Homa Wong

Jul 21 '05 #3
That is just a test code. The actual code like this

[DefaultValue(100)]
public int MaxValue
{
get{return Convert.ToInt32(txtValue.Text);}
}

With this, the designer report error because txtValue.Text is default
to "".
To the Convert.ToInt32() fails.

It works only if I set the txtValue.Text to "100" in the constructor.

Also, even if I do a test code like this,
#region Property TestVal
#region Comments
/// <summary>
/// Private -
/// </summary>
#endregion
private int _TestVal = 0;
#region Comments
/// <summary>
/// Gets or Sets (Default = 0)
/// </summary>
#endregion
[DefaultValue(100)]
public int TestVal
{
get{return _TestVal;}
set{_TestVal = value;}
}
#endregion

it still returns 0 in the Designer instead of 100.

Homa

Brendan Green wrote:
Well, your Getter is always returning 0, isn't it?

"Homa" <ho******@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I've create a custom DataGridColumnStyle and when I try to assign a
DefaultValue to a property, it doesn't seems to have any effect.

Here is the code:

[DefaultValue(10)]
public int Test
{
get{return 0;}
set{}
}

the default value shown is 0 instead.
I also tried [DefaultValue(typeof(int), "10")] with no effect.

Thanks,
Homa Wong


Jul 21 '05 #4

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

Similar topics

0
by: Gianluca | last post by:
Properties of inherited controls have the default value set to the value that is assigned in the InitializeComponent method in the base form class. Which is correct and useful. In the derived form...
0
by: vthakur | last post by:
Hello: I have generated a c# proxy (client) from the WSDL. One of the class has a defaultValueAtribute. Like so: public class PersonInformationLoadRequest { public string DataSource;
2
by: Mike in Paradise | last post by:
Can you use the DefaultValueAttribute on Decimal PropertyFields? If so what is format for setting the Default value. Thanks... Example /// <summary> /// Field: increment value ///...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
1
by: Mythran | last post by:
How can I set a DefaultValue for an array property? I don't have a project that uses this anymore, but still am curious. Of all the replies I've posted here, a simple thing like this is my...
2
by: --== Alain ==-- | last post by:
Hi, I would like to define the default value of my property. My property is from type Bitmap^, therefore i was thinking to do : but i does not work. how is it possible to define this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.