views:

20

answers:

1

hi, Considering the following classes:

 class A : Idata
 {
      private int _id;
      //other private fields

      public int Id
      {
            get { return _id; }
            set { _id = value; }
      }
      //other property
 } 
 class B : A
 {
      private int _field;
      //other private fields

      public int Field
      {
            get { return _field; }
            set { _field = value; }
      }
      //other property
  }

  class BCollection : Collection
  {
     ////
  }

I'm trying to bind a collection of B(which is composed out of A objects) to a datagrid and i get the following error: "Property accessor 'Id' on object 'A' threw the fallowing execption: 'Object does not match target type'" event though all the data from A gets to B

What should I do?

Thanks!

A: 

Hi,

i got it. it was my mistake this is how i fixed it Collection inherits from CollectionBase where i used the following contructor

 public IData this[int index]
        {
            get { return (IData)List[index]; }
            set { List[index] = value; }
        }

all i did was adding this in the B class

public B this[int index]
        {
            get { return (B)List[index]; }
            set { List[index] = value; }
        }
psu