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 / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

PropertyGrid and the base classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Olbert - 20 Jul 2007 03:42 GMT
Is there a way to pass a class to the SelectedObject of PropertyGrid and have
it only show the properties in the child class and not those in the base
class's that it is derived from?

Thanks.

Signature

John Olbert

A1b2c3d4@community.nospam - 20 Jul 2007 09:10 GMT
I don't know of any way.  You can control the behaviour of individual
properties in the grid via the Browsable and ReadOnly attributes in the
System.ComponentModel namespace.  I've always used a dedicated class as the
SelectedObject recipient.  The dedicated class would contain a reference to
your derived class instance.  It exposes properties equivalent to just those
on your derived class that you want to expose via the property grid.  You can
then decorate the properties on the dedicated class with attributes to
control the behaviour of the grid.  A good example of this would be when you
want a custom editor to be used for a property when its displayed in the grid.

This pattern is similar to how Microsoft does things in the Enterprise
Library configuration tool.  Briefly, they have hierarchies of classes
derived from System.Configuration.ConfigurationElement.  Each one does not
get exposed in a property grid directly.  Instead it has an equivalent
ConfigurationNode-derived class exposing just the properties that are to be
visible in the grid.

Hope this helps.

David Razzetti

> Is there a way to pass a class to the SelectedObject of PropertyGrid and have
> it only show the properties in the child class and not those in the base
> class's that it is derived from?
>
> Thanks.
Nicholas Paldino [.NET/C# MVP] - 20 Jul 2007 16:42 GMT
John,

   I would create a wrapper type which would implement
ICustomTypeDescriptor.  The implementation would take the object you are
looking to display in the property grid.  Then, using reflection, you would
pass back the properties, attributes, etc, etc, etc, which should be
displayed (a determination you would make through reflection, no doubt).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Is there a way to pass a class to the SelectedObject of PropertyGrid and
> have
> it only show the properties in the child class and not those in the base
> class's that it is derived from?
>
> Thanks.

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.