Paul Sasik
Paul Sasik

Reputation: 81489

How to display static (shared) object's properties in a PropertyGrid?

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?

Upvotes: 1

Views: 1549

Answers (1)

Jon Seigel
Jon Seigel

Reputation: 12401

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.

Upvotes: 5

Related Questions