Hi, I'm working on an application to edit name/value pairs using a property grid. Some of the properties in my class file are ListDictionary collections. Is there an Editor attribute that I can apply at the property declaration that will make the Collection Editor work at runtime? If not, is it possible to inherit from ComponentModel.Design.CollectionEditor for use at runtime? I need to be able to add, delete and edit the collection values. Thanks alot, Terry
I think that this article explains what you need: How to Edit and Persist Collections with CollectionEditor
from codeproject article [http://www.codeproject.com/KB/cs/dzcollectioneditor.aspx][1]
There are three requirements that a collection should meet in order to be successfully persisted with the CollectionEditor:
- First, the collection must implement the IList interface (inheriting from System.Collections.CollectionBase is in most of the cases the best option).
Second, it must have an Indexer (Item in VB.NET) property. The type of this property is used by the CollectionEditor to determine the default type of the instances that will add to the collection.
To better understand how this works, take a look at GetItemType() function of the CustomCollectionEditorForm:
protected virtual Type GetItemType(IList coll) { PropertyInfo pi= coll.GetType().GetProperty("Item", new Type[]{typeof(int)}); return pi.PropertyType }
Third, the collection class must implement one or both of the following methods: Add and AddRange. Although IList interface has an Add member and CollectionBase implements IList, you still have to implement an Add method for your collection, given that CollectionBase declares an explicit member implementation of the IList’s Add member. The designer serializes the collection according to what method you have implemented. If you have implemented both, the AddRange is preferred.
In this article you'll find everything you need to implement your collection on the property grid