crazyboybert
Programmer
Hi All
Ive got a requirement to bind a datagrid to a collection of objects of different type. They all implement the same interface and the DataSource is a custom collection derived from collection base of IMyInterface objects. The grid only uses properties from the interface to bind to and yet when bound throws the following exception:
System.Reflection.TargetException: Object does not match target type
So, I'm guessing the databind grabs the first object from the collection, uses reflection to find its most derived type and then assumes all of the objects in the collection are this type...?
So in this case no binding to base types or interfaces at all :-( or am i missing something. Never tried to do this before, always used custom types for collections when databinding.
Any good ideas short of handling the binding manually myself or something nasty like converting my collection into a datatable or suchlike?
Cheers
Rob
i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
Ive got a requirement to bind a datagrid to a collection of objects of different type. They all implement the same interface and the DataSource is a custom collection derived from collection base of IMyInterface objects. The grid only uses properties from the interface to bind to and yet when bound throws the following exception:
System.Reflection.TargetException: Object does not match target type
So, I'm guessing the databind grabs the first object from the collection, uses reflection to find its most derived type and then assumes all of the objects in the collection are this type...?
So in this case no binding to base types or interfaces at all :-( or am i missing something. Never tried to do this before, always used custom types for collections when databinding.
Any good ideas short of handling the binding manually myself or something nasty like converting my collection into a datatable or suchlike?
Cheers
Rob
i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...