Binding Multiple Types To DataGrid

Binding Multiple Types To DataGrid

Post by gargame » Wed, 26 May 2004 01:38:15


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.
 
 
 

1. string collection data to bind to, datagrid already binded to type

2. Column order when binding DataGrid with typed collection

I need help for setting the order of columns in a
DataGrid populated by binding it with a fixed-type
collection of custom objects. Actually I don even know
where to start.
The binding was easy and works with a simple

myDataGrid.DataSource = myCollection;

But the order of the columns messes the data; related
columns appear separated each other. How can I specify
column ordering? Should I change the order in the
DataGrid (How?). Or there is a way to make Reflection
work automatically on the type to get the properties and
fields on the right order, so whenever I bind them with a
grid the columns appear in the right place?

3. Datagrid Binding Error: "Object does not match target type."

4. DataGrid Binding Problem : "Object does not match target type."

5. string collection data to bind to, datagrid already binded to typed dataset

6. UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback

7. Array bound to Datagrid - getting values out of the datagrid

8. DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP

9. custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid

10. threading, what different between DataGrid Binding to Binding TextBox

11. DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP

12. Multiple Row Deletion on DBGrid Data type Bound

13. Datagrid with multiple row types

14. apply vs destructuring-bind vs multiple-value-bind

15. Accessing type-bound procedures of parent types