Binding Multiple Types To DataGrid

G

Gargamel

Hi.

In my webapp, I have several types of object that derive from an
abstract base class.

abstract class CMSItem
class Page : CMSItem
class Folder : CMSItem
class Site : CMSItem

This base class contains some abstract fields, Id, Title, IconFileName
which are all overriden in the subclasses.

I have an array of CMSItem objects, which I want to bind to a
DataGrid. The only properties I'm trying to access on the datagrid
are ones which are in the base CMSItem type. But when I try and bind
I get:

System.Reflection.TargetException: Object does not match target type.

Why is this? Does the DataGrid only bind when all objects are of the
same class?

This is really annoying. As a workaround I'm thinking that I may have
to create a specific class for displaying these items in the DataGrid,
and have some static method which can convert items of CMSItem to some
non abstract type, but I'm surprised that what I'm doing isn't
working.

Any ideas?

Many thanks.

R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top