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?
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
Applicationobject and using that as a data source instead.