PropertyGrid and the base classes

G

Guest

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.
 
G

Guest

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
 
N

Nicholas Paldino [.NET/C# MVP]

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top