Mital Kakaiya [MCSD.NET]
In Programming, Logic is everything.

Developing a custom collection editor

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.



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Developing a custom collection editor

Any chance of getting your code? 8/18/2005 8:32 AM | SBendBuckeye

# re: Developing a custom collection editor

Thanks for your interest for .NET Custom Collection editor. I would love to share my source-code with everyone, but I could not share full source-code as part of my job's commitment. I am happy to help you for any issues/queries you have. 8/22/2005 7:46 PM | Mital Kakaiya [MCSD.NET]

# re: Developing a custom collection editor

Am I missing something? Why is System.Data.ColumnCollection not available to me? Ihave a reference to System.Data.dll.

9/16/2005 5:13 AM | Israel DiPeri

# re: Developing a custom collection editor

Hi Israel,

Thanks for your query.

ColumnCollection is a custom collection of Column class, which is inherited from CollectionBase class. This class is not inside System namespace.

I use CodeSmith to generator strongly-typed collection for each class eg: Column to ColumnCollection class, Field to FieldCollection class.
9/17/2005 6:46 AM | Mital Kakaiya [MCSD.NET]

# re: Developing a custom collection editor

You should use IWindowsFormsEditorService to display the dialog, i.e. edSvc.ShowDialog(_collectionEditor) 12/2/2005 3:43 AM | Nate Rickard

# re: Developing a custom collection editor

Hi Mital
I'm trying to make my own Collection Designer. But it dont work. The Collection is after Editing it in my Collection Editor always empty.

I'm interesetes at our Sample.
Can you send me your sample?

Best regards Horst 8/29/2006 5:24 PM | Horst Klein

# re: Developing a custom collection editor

I see that you could create custom events with the collection editor using ComponentChange. But how do you use that event from the form?

For example, I'd like to know when an item is added to the collection and have the form do something when that happen. How would I do that?

Is it possible to get some sample of your codes?

Thanks 10/11/2007 4:57 AM | ST

Comments have been closed on this topic.