Windows Develop Bookmark and Share   
 index > Windows Forms Designer > DefaultValue question
 

DefaultValue question

Hello,

is there any possibility to tell Designer not to serialize default values of properties when I override the default value on derived type? Here is mine (working but long) implementation:

public class GDataGridView : DataGridView

{

public GDataGridView()

{

MultiSelect = false;

}

[DefaultValue(false)]

public new bool MultiSelect

{

get { return base.MultiSelect; }

set { base.MultiSelect = value; }

}

Any possibility to do the same without new property override?

Thanks in advance,

Martin

maliger  Tuesday, January 22, 2008 3:04 PM

I don't believe that a "nice" way of handling this, as you suggest, exists.

Basically, I think that there are three cases:

1. The base class property was declared overridable. In this case you can use "overrides".

2. The base class property was not declared overridable. In this case you can use "new", as shown in your example, since the designer only looks at the most derived class in the hierarchy.

3. You could implement a bool function, ShouldSerializeYourPropertyName(). The designer specially recognizes such functions. This function may require "overrides", "new", or neither depending on whether the base class already has such a function and whether it was declared overridable.

I have often used solution #2, as you have chosen, to solve this kind of problem.

BinaryCoder  Thursday, January 24, 2008 12:04 AM

I don't believe that a "nice" way of handling this, as you suggest, exists.

Basically, I think that there are three cases:

1. The base class property was declared overridable. In this case you can use "overrides".

2. The base class property was not declared overridable. In this case you can use "new", as shown in your example, since the designer only looks at the most derived class in the hierarchy.

3. You could implement a bool function, ShouldSerializeYourPropertyName(). The designer specially recognizes such functions. This function may require "overrides", "new", or neither depending on whether the base class already has such a function and whether it was declared overridable.

I have often used solution #2, as you have chosen, to solve this kind of problem.

BinaryCoder  Thursday, January 24, 2008 12:04 AM
Thank you,

world is not ideal. I just think this is quite general pattern so some recommended solution should be around.

Thanks again

maliger  Tuesday, February 12, 2008 9:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Determining image type which was saved in resources
• How to do parallel transactions in SQL server database using VB.Net 2005?
• Where are windows forms controls icons stored?
• Context Menu With DataGridView
• Hosting designers and IToolboxService question
• Status Strip Blacking Out Issue on Windows Vista
• Control Layout problem
• Controls are not visable in .net code
• String Collection Editor
• VS2005 anchor problems on inherited form with a tab control