Modifying CollectionEditor in PropertyGrid
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-03-05T19:42:26Z
Indexed on
2010/03/26
7:33 UTC
Read the original article
Hit count: 409
c#
|collectioneditor
I currently have a list containing Call's, which is the base class. If I want to add derived classes of Call to the list, I know to do the following.
public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor
{
private Type[] types;
public CustomCollectionEditor(Type type)
: base(type)
{
types = new Type[] { typeof(Call), typeof(CappedCall) };
}
protected override Type[] CreateNewItemTypes()
{
return types;
}
}
public class DisplayList
{
public DisplayList() { }
[Editor(typeof(CustomCollectionEditor), typeof(UITypeEditor))]
[DataMember] public List<Call> ListCalls { get; set; }
}
My questions is there anyway of moving where you mark up the Type[] containing all possible types the list can contain? I thought of adding the following to my CustomCollectionEditor class, but this doesn't work.
public CustomCollectionEditor(Type type, List<Type> types_)
: base(type)
{
types = types_.ToArray();
}
It would be ideal if I could mark up which classes the CustomCollectionEditor needed to be aware of in the DisplayList class somehow.
© Stack Overflow or respective owner