I have a collection of objects which has the following structure:
public class Parent
{
public string Title { get; set; }
public string Guid { get; set; }
}
public class Child:Parent
{
public string Description { get; set; }
}
List<Parent> collection ;
collection = new List<Parent>();
collection.Add(new Parent());
collection.Add(new Parent());
collection.Add(new Child());
collection.Add(new Child());
collection.Add(new Parent());
So some elements are from Parent type and some from Child type(I have inheritance relationship among the objects in the collection).
I used the following bindings:
txtTitle.DataBindings.Add("Text", _BindingSource, "Title");
txtGuid.DataBindings.Add("Text", _BindingSource, "Guid");
txtDescription.DataBindings.Add("Text", _BindingSource,"Description");
First two bindings obviously work fine. But what should I do to the third one to display the data properly?
In his book “Data Binding with Windows forms 2.0”, p. 125, author Brian Noyes says that items in a BindingSource must be homogenous, ie of the same type.
It would seem what you’re trying to do is not possible, at least not with a BindingSource component.