I have bound a DataGrid to a BindingList property typed to a base type. Within the 'get' accessor, I construct a BindingList with elements of a derived type and then return this BindingList using the LINQ extension method Cast() to cast it to the property's BindingList base type. The reason I do this is so that I retain the binding to the same property, but show collections of different element types depending on the scenario.
The bound data displays correctly in the grid as one would expect. However, the Excel export doesn't export the correct data. For the column of the derived class's property, it actually exports the base class's property value, even though this has already been exported to another column as it should be. I have attached an example project demonstrating this behaviour.
It seems to me that the type that the BindingList is typed to is having its properties iterated through using reflection when exporting the data rather than the type of each individual element, even though the type of each individual element is being used for the property count for iteration purposes during the reflection process. Just a guess.
Could this please be investigated?
Thanks,
Jason
Associate, .NET Development
Morgan Stanley, UK