By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

Very Advanced PropertyGrid control use

P: n/a
Herfried K. Wagner was kind enough to point me to the PropertyGrid control
http://msdn.microsoft.com/library/en...classtopic.asp

I have found a few samples of how to use the PropertyGrid control and have gained a decent understanding of it. But of course, as it usually the case, my needs go far beyond the simple examples shown in online samples. All the online samples show how to take a class with already defined properties and to add metadata attributes. My case is very different.

The basic structure for my classes are:

Class GenericToolObject
Readonly Property IsContainer
Readonly Property Enabled
Readonly Property ShowInToolBox
...few others...
Readonly Property Properties() as ToolObjectProperties

Class ToolObjectProperties
(basically just a collection class of ToolObjectPropertyInfo objects)

Class ToolObjectPropertyInfo
Readonly Property Index
Readonly Property Name
Read/Write Property Value ****
Readonly Property Type (as an enumeration type)
...few others...

Instances of GenericToolObjects and its property definitons are loaded at run-time from XSD files. When an object is edited, the property editor will basically need to display the collection of ToolObjectProperties for the GenericToolObject in the PropertyGrid control, showing the ToolObjectPropertyValue.DisplayName on the left, and the ToolObjectPropertyInfo.Value on the right.

I don't see how adding metadata attributes to my classes will do any good, because the information for property category, descriptions, etc comes from the XSD files which are not loaded until runtime.

Can a PropertyGrid control be controlled to the level I need it such that I can tweak it at run-time to render the property categories, descriptions, etc at run-time without metadata attributes? For an initial prototype I basically created my own property editor which renders labels, textboxes, combobox, checkboxes, datagrids etc to represent the properties for a GenericToolObject instance. The VS.Net PropertyGrid control though is so much nicer and more professional looking. I could indeed update my own property editor to render better and to support property groups and the like, but I am wondering if it would be easier to just use the PropertyGrid control for this purpose.

Any help would be greatly appreciated and of course I will share the solution to this if there is one. I get the feeling that I'm the first to delve into this territory and use of the PropertyGrid control.

Thanks,
Andres

**************************************
Andrés Becerra
Pennsylvania, USA
Email not posted due to email stealing A**H***S that poll newsgroups.
**************************************
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jay,

You are a king among men sir. You did indeed point me in the right
direction. After some research into the ICustomTypeDescriptor interface, I
came across this article which gave me a working example to learn from.

http://www.codeproject.com/cs/miscct...=100&tid=40951
1&forumid=13899&select=409511#xx409511xx

Thanks again!!

--
**************************************
Andrés Becerra
Pennsylvania, USA
Email not posted due to email stealing A**H***S that poll newsgroups.
**************************************
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:#n**************@tk2msftngp13.phx.gbl...
Andres,
I do not have a clean example handy.

I believe you need to use the ICustomTypeDescriptor interface. This
interface allows you to dynamically return a list of properties for the
object you are displaying in the Property Grid.

I use ICustomTypeDescriptor to return a list of properties for an object
proxy, which works. For the categories & Descriptions I believe you will
need to override the ICustomTypeDescriptor.GetAttributes method.

My concern is there are one or two other interfaces you need. I use
ICustomTypeDescriptor for some custom data binding to the data grid, I have a proxy object that I just delegate most of the ICustomTypeDescriptor
methods to the actual object. (Via TypeDescriptor)

I took my project and put together a very quick form that uses the property grid and it seems to work, however I do not have attributes, so I'm not sure about that.

Hopefully this enough to get you headed in the right direction! ;-)

Hope this helps
Jay

"ANDRES BECERRA" <a.*******@sap.com> wrote in message
news:be**********@news1.wdf.sap-ag.de...
Herfried K. Wagner was kind enough to point me to the PropertyGrid control
http://msdn.microsoft.com/library/en...windowsformspr
opertygridclasstopic.asp
I have found a few samples of how to use the PropertyGrid control and have
gained a decent understanding of it. But of course, as it usually the case, my needs go far beyond the simple examples shown in online samples. All the online samples show how to take a class with already defined properties and to add metadata attributes. My case is very different.

The basic structure for my classes are:

Class GenericToolObject
Readonly Property IsContainer
Readonly Property Enabled
Readonly Property ShowInToolBox
...few others...
Readonly Property Properties() as ToolObjectProperties

Class ToolObjectProperties
(basically just a collection class of ToolObjectPropertyInfo objects)

Class ToolObjectPropertyInfo
Readonly Property Index
Readonly Property Name
Read/Write Property Value ****
Readonly Property Type (as an enumeration type)
...few others...

Instances of GenericToolObjects and its property definitons are loaded at
run-time from XSD files. When an object is edited, the property editor will basically need to display the collection of ToolObjectProperties for the
GenericToolObject in the PropertyGrid control, showing the
ToolObjectPropertyValue.DisplayName on the left, and the
ToolObjectPropertyInfo.Value on the right.

I don't see how adding metadata attributes to my classes will do any good,
because the information for property category, descriptions, etc comes from the XSD files which are not loaded until runtime.

Can a PropertyGrid control be controlled to the level I need it such that I can tweak it at run-time to render the property categories, descriptions,
etc at run-time without metadata attributes? For an initial prototype I
basically created my own property editor which renders labels, textboxes,
combobox, checkboxes, datagrids etc to represent the properties for a
GenericToolObject instance. The VS.Net PropertyGrid control though is so
much nicer and more professional looking. I could indeed update my own
property editor to render better and to support property groups and the
like, but I am wondering if it would be easier to just use the PropertyGrid control for this purpose.

Any help would be greatly appreciated and of course I will share the
solution to this if there is one. I get the feeling that I'm the first to
delve into this territory and use of the PropertyGrid control.

Thanks,
Andres

**************************************
Andrés Becerra
Pennsylvania, USA
Email not posted due to email stealing A**H***S that poll newsgroups.
**************************************

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.