I have a grid populated from a base class. The base class has a enum property to identify what type of derived object it is. When the user adds a new row and changes that enum value, I need to replace the object with the associated derived type. Example:
public enum ObjectType
{
Base,
ChildA,
ChildB
}
public class Base
{
public ObjectType Type { get; set; }
}
public class ChildA : Base { }
public class ChildB : Base { }
The grid will initially create a new row with a DataBoundObject of Type 'Base'.
When the the user changes the 'ObjectType' column to 'ObjectType.ChildA' I need to replace the row's DataBoundObject with a new instance of 'ChildA'.
The grid's DataSource is set to a BindingSource; who's DataSource is set to BindingList<Base>.
I tried to replace the object in the BindingList. Then set the BindingSource.DataSource to the updated BindingList. And then call BindingSource.ResetBindings(false) to updated the GridView. But I receive a NullReferenceException.
How can I replace the Row's DataBoundObject with a derived object?