Newbie question on the PropertyGrid Control

D

Dom

Can the PropertyGrid control be customized? I want the user to click
on an object, eg, a text box, and then have the property box come up
with my own list of properties that make sense only within the
application.

A property might be "Type of Question", and values should appear in a
drop down list. And so on.

Thanks in advance,
Dom
 
L

Larry Smith

Can the PropertyGrid control be customized? I want the user to click
on an object, eg, a text box, and then have the property box come up
with my own list of properties that make sense only within the
application.

A property might be "Type of Question", and values should appear in a
drop down list. And so on.

Thanks in advance,

Yes you can. The "PropertyGrid" is easily the most confounding control I've
ever used however and it's difficult to get your head around all the
details. This is mainly due to a lack of proper documenation combined with
the fact that a property grid is mostly fed by the properties and attributes
of the object you pass it (unlike normal controls). You therefore need to
undertand how to feed it by preparing your objects accordingly. This
involves a lot of work with .NET reflection and other low-level details.
MSFT could have (and should have) simplified many common aspects of the
process but they didn't. Prepare for some pain IOW and several weeks of work
depending on the extent of what you want to do and whether you really want
to gain a full understanding of the issues involved (opposed to simply
copying some example without fully appreciating it). Here's an article for
starters. Many others exists on the web of course and I've got plenty of
them saved locally (tackling different issues). Good luck.

http://msdn2.microsoft.com/en-us/library/aa302334.aspx#vsnetpropbrow_topic01
 
V

VisualHint

Dom,

you will find a good amount of informations on the PropertyGrid
resource list (http://www.propertygridresourcelist.com), arranged by
tags.

Basically you will have to bind the grid to your instance with
SelectedObject. Your properties will be decorated with attributes to
alter the way they are displayed and edited. If you need a listbox
with a set of possible values, an enumeration will do the trick. If
this is not the type of your property, you will certainly create and
attach a TypeConverter to it that will publish this set of values.
Many things are feasible with this control, you should really read
some resources listed on the mentioned web site.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
 
L

Larry Smith

Basically you will have to bind the grid to your instance with
SelectedObject. Your properties will be decorated with attributes to
alter the way they are displayed and edited. If you need a listbox
with a set of possible values, an enumeration will do the trick. If
this is not the type of your property, you will certainly create and
attach a TypeConverter to it that will publish this set of values.
Many things are feasible with this control, you should really read
some resources listed on the mentioned web site.

Unfortunately, due to the inherent nature of the control coupled with
various design shortcomings, multiple ways of handling certain issues (which
only adds to the confusion), the inability to customize certain aspects of
the control (you can't change the color or font of individual rows for
instance), the inability to easily validate your properties (something as
simple as a range check on an "int' for instance), outright bugs which I
reported to MSFT, and worst of all perhaps, a woeful lack of comprehensive
documentation, it's very difficult to get a solid grip on all the issues
involved. A "TypeConverter" is only the beginning. The control is needlessly
complicated and I personally banged my head for 3+ weeks trying to figuring
it all out (with some issues still eluding me though I finally got it
working).
 
V

VisualHint

Your're right Larry. The control can become very complex as soon as
your needs become complex also. This is why I created Smart
PropertyGrid at first: avoid the shortcomings and the complexity of
the native control. All the limitations you mentioned are handled and
various creation modes really decrease the complexity.
Anyway I didn't want to frighten Dom. He can show simple properties
easily, all depends on his needs...

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
 
L

Larry Smith

Your're right Larry. The control can become very complex as soon as
your needs become complex also. This is why I created Smart
PropertyGrid at first: avoid the shortcomings and the complexity of
the native control. All the limitations you mentioned are handled and
various creation modes really decrease the complexity.
Anyway I didn't want to frighten Dom. He can show simple properties
easily, all depends on his needs...

While it's an enterprising, money-making venture for you personally (with
all due credit), it shouldn't have been necessary. MSFT should have
simplified their own control in the first place.
 
V

VisualHint

This is obvious Larry. I wonder if at first MS thought that their
PropertyGrid could be used so much 1. in developer tools (used by
developers) and 2. in desktop applications (used by end-users, will
all the usability issues we know)...

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
 

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