Hi,
I am creating a windows forms component with properties that do NOT
have default values at design-time. The type of these properties are
the primitive types (ie bool, double, int etc).
public class MyComponent : Component
{
public bool EnableSessionState
{
...
}
}
At design-time, I would like to show a "blank" value for the
'EnableSessionState' property. I would like to serialize code only when
the user explicitly chooses the value to "true" or "false" (via the
drop-down).
The behaviour I am looking at, is similar to the Debug property on the
PageSection type in ASP.NET. The property accepts an empty string at
design-time, but the value gets serialized only when the value is set
to true or false.
BGM
Frank Hileman - 30 Dec 2005 18:35 GMT
Hello,
Your property cannot be a boolean in this case. Use a custom enum,
containing Enabled, Disabled, Default. Create a custom TypeConverter so only
True and False are shown. Override the CanConvertTo and ConvertTo for the
string case and produce an empty string in the case of Default.
Have the default value attribute set to Default.
In the general sense, the property grid does not support "not set"
properties, except in the case of object references, where "not set" can be
specified with a null reference. For a boolean you can fake it with an enum,
but for other types you will have to use a struct or object wrapper with a
boolean field. Alternatively, use a single property with nested properties
inside, with a custom UITypeEditor that pops up a dialog, whereby you can
use your own controls with a "not set" value. But internally you will need
booleans or bitflags to keep track of which properties are set (and should
be serialized) and which are not, and you will need public methods to reset
properties to their not set state.
Regards,
Frank Hileman
check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
> Hi,
>
[quoted text clipped - 21 lines]
>
> BGM