Hello group!
I got a little question for you all...
I've created two classes (FirstCollection and SecondCollection) that implements some interfaces: IBindingList, IList, ICollection, IEnumerable and ITypedList.
In my FirstCollection class, the method ITypedList.GetItemProperties(..) returns a PropertyDescriptorCollection object, so I've created a class MyFirstItemPropertyDescriptor that derives from PropertyDescriptor.
I'll show you a little bit of code:
class MyFirstItemPropertyDescriptor : PropertyDescriptor
{
public MyFirstItemPropertyDescriptor(string propertyName) : base(propertyName, null)
{
}
public override System.Type ComponentType
{
get { return typeof(MyFirstItem); }
}
public override System.Type PropertyType
{
get
{
Type type = null;
switch(this.Name)
{
case "Column1":
type = typeof(string);
break;
case "Column2":
type = typeof(int);
break;
case "ChildItems":
type = typeof(IBindingList);
break;
}
return type;
}
public override object GetValue(object component)
{
return component.GetType().GetProperty(this.Name).GetValu e(component, null);
}
}
}
For the ITypedList implementation in my SecondCollection class I've created a class named MySecondItemPropertyDescriptor derived from PropertyDescriptor too.
Besides, both MyFirstItem and MySecondItem classes implement the ICustomTypeDescritor interface and the method ICustomTypeDescriptor.GetProperties(..) returns the same PropertyDescriptorCollection object returned by the container collection in its method ITypedList.GetItemProperties(..).
I want each item in my FirstCollection object to have a property that stores a SecondCollection object (like DataRowView objects (contained in DataView objects) that have other DataView object associated).
When I test my FirstCollection object as a DataSource for the DataGrid control, I can edit each column coming from the PropertyDescriptorCollection returned by the ITypedList interface, and I can even see a plus icon in the left side of each row, and when I expand it I can see some kind of "hyperlink" with the name of my SecondCollection object.
The problem arises when I click the "hyperlink"; the DataGrid control tries to edit a MySecondItem object, but keeping the columns of the MyFirstItem objects and an exception of type System.Reflection.TargetException is thrown.
I'm developing an important project so I will really appreciate any help...
Thank you all...