views:

65

answers:

1

I would like to display static (shared) objects at runtime in a PropertyGrid but if I try to set the selected object property of the grid like this:

_propertyGrid.SelectedObject = System.Windows.Forms.Application

I get a compilation error:

'Application' is a type and cannot be used as an expression.

Is there a way to display a static (shared) object or the object's properties in the PropertyGrid?

+3  A: 

That assignment statement really doesn't make sense from an OO-perspective because a static object really isn't an object -- it's just a collection of methods and properties without any kind of coherence except for the class name. I see what you're trying to do, though.

You need to give it an object instance.

I would suggest creating a wrapper class (possibly a singleton) that exposes the properties you need from the Application object and using that as a data source instead.

Jon Seigel
This is an interesting OOP question that i never actually had to think about before. Besides trying to display a static object in the grid view this question also applies more broadly to something like passing static objects as function arguments. Looks like you can't. Not in .NET anyway.
Paul Sasik
@Paul: I updated my answer to be more explicit.
Jon Seigel