Live Chat Icon For mobile
Live Chat Icon

How can I allow my user to add more than 1 type of object to my collection, during design-time?

Platform: WinForms| Category: Type Editors

The default CollectionEditor will allow your user to add objects of type returned by your collection’s indexer method.

You can make this CollectionEditor allow your user to pick the type of object to add by deriving from CollectionEditor and making the change as shown below. This will introduce a drop-down in the editor’s ‘Add’ button to allow the user to pick the type he wants to add.

public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor
	private Type[] types;
	public CustomCollectionEditor(Type type)
		: base(type)
		types = new Type[]{typeof(ItemType1), typeof(ItemType2), typeof(ItemType3), 

	// Return the types that you want to allow the user to add into your collection.
	protected override Type[] CreateNewItemTypes()
		return types;

[Editor(typeof(CustomCollectionEditor),  typeof(UITypeEditor))]
public class CustomCollection : IList

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.