471,348 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 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 1840
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gianluca | last post: by
2 posts views Thread by Mike in Paradise | last post: by
5 posts views Thread by Martin Heuckeroth | last post: by
5 posts views Thread by tshad | last post: by
8 posts views Thread by jojobar | last post: by
2 posts views Thread by Don | last post: by
1 post views Thread by Mythran | last post: by
2 posts views Thread by --== Alain ==-- | last post: by
1 post views Thread by Ronak mishra | last post: by

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.