I’m trying to make an editor for a game which has an event system, with a base class for the events and then another class for each kind which actually do all the stuff.
So, I have a list of BaseEvent which shows in a PropertyGrid, and as a list, the collection editor opens. I prepared a TypeConverter so I have a dropdown with all derived classes which shows in the “Value” property.
Everything is OK, properties from derived classes show as children of “Value”, but as soon as I want to show a property from BaseEvent, the “Value” property disappears, and children appear at the root, so I’m unable to change the type of the event.
Is there a way to make the “Value” property appear at the same time as the BaseEvent properties?
//This allows to get a dropdown for the derived classes
public class EventTypeConverter : ExpandableObjectConverter
{
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(GetAvailableTypes());
}
/*
...
*/
}
[TypeConverter(typeof(EventTypeConverter))]
public abstract class BaseEvent
{
public bool BaseProperty; //{ get; set; } If I set this as a property, "Value" disappears
}
public class SomeEvent : BaseEvent
{
public bool SomeOtherProperty { get; set; }
}
//The object selected in the PropertyGrid is of this type
public class EventManager
{
public List<BaseEvent> Events { get; set; } //The list that opens the collection editor
}
Finally I found a way to solve this: through the GetProperties method, and a custom PropertyDescriptor: