I'm trying to create an extended version of the WinForms DataGridView (ElementDataGrid) to allow sorting and filtering. Since this will be a widget used by multiple developers, I want to hide the SortableBindingList class internally and have the user pass in just a normal List with the control creating the SortableBindingList.
I created a base class called Element, which other developers can extend, but when I set the DataPropertyName of a column to a property that isn't in Element, nothing shows up in that column. As an example, I have a Comment class that inherits from Element. I want to display the Comment Date and Comment Text in the datagrid. Neither of those columns have any data in them, but the columns using properties inherited from Element display properly.
Is there a straightforward way to have the grid display property values from classes that inherit from the Element base class? Alternately, is there a way I could have the property take a generic List?
UPDATE: Here's the method I'm using to set the data source to my SortableBindingList. As I said, properties from Element are being populated in the grid when I want to show them, but properties from Comment, which inherits from Element are not.
public List<Element> DataElements
{
set
{
bindingDataSource.Clear();
SortableBindingList<Element> boundDataSource = new SortableBindingList<Element>();
bindingDataSource.DataSource = boundDataSource;
foreach (Element e in value)
{
bindingDataSource.Add(e);
}
this.DataSource = bindingDataSource;
}
}