Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / December 2005

Tip: Looking for answers? Try searching our database.

Properties without default values at design-time

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bgm - 29 Dec 2005 12:36 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.