Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using PropertyGrid to populate a complex object, whose types I do not know at compile time. For collections, the PropertyGrid invokes the default property grid collection editor. I need to intercept or replace that so I can react to edits of the fields within the collection. This would not be difficult if I knew the types, as I could write a bespoke collection editor, but can I achieve this without knowing the types? For example, could I write one CollectionEditor that all collections will utilize?

All the collections are of type Generic.List<T> for varying T.
Posted
Updated 27-Oct-14 6:10am
v2
Comments
Sergey Alexandrovich Kryukov 27-Oct-14 12:26pm    
This is important and interesting question, I voted 5 for it.
I described nearly all the ideas you need to get, in my article I referenced in my answer.
I cannot immediately provide your the code sample closer to the kind of editor you need, sorry. I hope you can use the techniques I describe and do it all yourself. In all cases, your follow-up questions will be welcome.
—SA
BillWoodruff 28-Oct-14 4:14am    
"I need to intercept or replace that so I can react to edits of the fields within the collection." I interpret this to mean you want event notifications ... which you can cancel ? ... over-ride ? ... of actions in a PropertyGrid CollectionEditorWindow for each 'Click of the 'Add, 'Remove buttons, or for each 'Click when the user uses the up- down- buttons to change the order of items ?

Is that correct ?

1 solution

Customization of PropertyGrid is quite doable but not so easy. However, it you just want to develop your own editor, this is much simpler. You develop the editor for your type(s), write a special attribute and apply it to the type(s). If you do so, you won't need to add this attribute to the members of those type. This will automatically cover all types using your special types for their members — all such (unknown in advance) members will use your editor.

How to do this? If have a very detailed explanation with full source code, which is relatively short and easy. It least the idea is easy to catch. Please see my recent article: Bitwise Enumeration Editor for PropertyGrid and Visual Studio[^].

If you have other questions on PropertyGrid customization, I'll try to answer, but some sort of customization is relatively hard to explain without source code. I do have such code, but it will take a lot of time to adopt it for an article.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900