Sunday, July 03, 2005 1:15 AM
.NET framework has a collection editor, which provides design-time user interface to edit most types of collections. Last month, I needed custom collection editor at design-time, including hidden Add/Remove buttons, custom properties events, collection item validation rules etc...
I have designed a custom collection editor form called "CollectionManager", which fires custom events as follow:
Now, create a "Columns" property inside usercontrol with EditorAttribute tag as follow.
Editor attribute provides a type of the class to creates an instance, which is inherited UITypeEditor class. Now, implementing CustomCollectionEditor class is really simple.
Now, it requires to override GetEditStyle function. This function indicates PropertyGrid to display design-time editor type for this property. As it's a colleciton editor, it should be UITypeEditorEditStyle.Modal style.
Also, it needs to overrides EditValue function, which calls to handle collection's edit request. To implement this EditValue function, it needs to create an instance of custom collection editor form called "CollectionManager".
When user changes collection value and need to serialise CodeDOM properly, it is important to call context.OnComponentChanging() function and context.OnComponentChanged() functions to notify "forms designer" about these changes.