More PropertyGrid Agony

R

Ron M. Newman

Hi,

Can the native PropertyGrid accept dynamic properties? ones that are not
pre-compiled into a class and don't have those [TAGS] thingies attached to
properties? Can I just instantiate a property grid and put a dynamic "Name"
property in there without having a class with a name property "fed" to it?

Thanks
Ron
 
R

Ron M. Newman

...oh. and I can't use a 3rd part tool. I must work off of the native
property grid.
 
J

Jon Shemitz

Can the native PropertyGrid accept dynamic properties? ones that are not
pre-compiled into a class and don't have those [TAGS] thingies attached to
properties? Can I just instantiate a property grid and put a dynamic "Name"
property in there without having a class with a name property "fed" to it?

Yes. The API is complex, but you can create 'virtual' properties; set
arbitrary display text; enable and disble; hide and show.
 
R

Ron M. Newman

Hi,
Yes. The API is complex, but you can create 'virtual' properties; set
arbitrary display text; enable and disble; hide and show.

How? any hints? is it by "simulating" properties using the
ICustomTypeDescriptor interface? or is there another way?

Thanks
Ron

Jon Shemitz said:
Can the native PropertyGrid accept dynamic properties? ones that are not
pre-compiled into a class and don't have those [TAGS] thingies attached
to
properties? Can I just instantiate a property grid and put a dynamic
"Name"
property in there without having a class with a name property "fed" to
it?

Yes. The API is complex, but you can create 'virtual' properties; set
arbitrary display text; enable and disble; hide and show.
 
J

Jon Shemitz

Ron M. Newman said:
How? any hints? is it by "simulating" properties using the
ICustomTypeDescriptor interface? or is there another way?

It's been a couple years, so my hint is www.google.com. As I recall,
there was a "property bag" project that didn't have any code we could
actually use, but which pointed in the right direction.

If you're really clueless, I could look at my old code and post some
more tips, but I can't post the old code because I don't own it.
 
D

Dave Sexton

Hi Ron,

Yes, ICustomTypeDescriptor or you can create a TypeConverter for your class.
Each can be used to create a PropertyDescriptorCollection which contains all
of the properties to be used by the PropertyGrid.

You can create PropertyDescriptors that don't have any true property backing
by deriving a class from TypeConverter.SimplePropertyDescriptor (nested,
protected abstract class. You can derive a class that is nested in another
custom class that must derive from TypeConverter). If you don't need a custom
TypeConverter or if you just want a "cleaner" method of creating custom
property descriptors, just derive a class from PropertyDescriptor.

--
Dave Sexton

Ron M. Newman said:
Hi,
Yes. The API is complex, but you can create 'virtual' properties; set
arbitrary display text; enable and disble; hide and show.

How? any hints? is it by "simulating" properties using the
ICustomTypeDescriptor interface? or is there another way?

Thanks
Ron

Jon Shemitz said:
Can the native PropertyGrid accept dynamic properties? ones that are not
pre-compiled into a class and don't have those [TAGS] thingies attached to
properties? Can I just instantiate a property grid and put a dynamic
"Name"
property in there without having a class with a name property "fed" to it?

Yes. The API is complex, but you can create 'virtual' properties; set
arbitrary display text; enable and disble; hide and show.
 
D

Dave Sexton

Hi Ron,
pre-compiled into a class and don't have those [TAGS] thingies

Those "[TAGS] thingies" you are referring to are called Attributes. You can
create custom Attributes as well by deriving from the Attribute class to
associate custom meta-data to your classes, structures, enums, their various
members, method arguments, return values, etc.

Attributes are extremely important in managed code, so I suggested that you
research them ASAP and make sure that you understand them.

Even if you don't create your own they are used frequently in the FCL for
various reasons such as CAS, support for the compiler, COM-interop, debugging,
data-binding, serialization, custom meta-data, to supply information about
properties to the PropertyGrid, etc.

--
Dave Sexton

Ron M. Newman said:
Hi,

Can the native PropertyGrid accept dynamic properties? ones that are not
pre-compiled into a class and don't have those [TAGS] thingies attached to
properties? Can I just instantiate a property grid and put a dynamic "Name"
property in there without having a class with a name property "fed" to it?

Thanks
Ron
 
B

Bob Powell [MVP]

PropertyGrid will display any properties you hand to it.

Changes to the .NET 2.0 system have greatly increased the usefulness of the
TypeDescriptor. You should check out the TypeDescriptionProvider system.

Essentially you can expose properties, filter them, change them even add
totally artificial ones and the PropertyGrid will enable you to edit them.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

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