Hi

 I was wondering if there was any approach to bind an object that contains a
nested object within. Suppose class A is defined as

 class A
{
    .
    .
    .
  //Property that exposes nested object
  public B prop
    {
         get{return new B();}
    }
}

and class B is defined as

class B
{
    //Properties corresponding to B
    public int x
    {
        get{return 1;}
    }
    .
    .
    .

}

If I were to bind a strongly typed collection of object A  and try to bind
the collection, the property that exposes the nested object, does not show
the values. What would I require to do if I want to bind collection of A
where the properties of B are included as a "joined view" . I tried
implementing TypeConvertor and override GetProperties, but Iam unable to add
to the propertydescriptorcollection since it is not implemented.

I was wondering if there was any other approach to this whole problem. This
seems like a common scenario.

public class NestedPropertyConverter : TypeConverter
{
public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context,object value, Attribute[]
filter)
{
 //Obtain the default property descriptors, add nested properties and return
 PropertyDescriptorCollection  props = TypeDescriptor.GetProperties(value,
filter);

 for(int i=0; i<props.Count; ++i)
 {
 PropertyDescriptor desc = props[i];
 if(desc.PropertyType == Type.GetType("B"))
 {

 PropertyDescriptorCollection  nestedProps =
TypeDescriptor.GetProperties(desc.PropertyType);

 for(int j=0; j<nestedProps.Count; ++j)
 {
  PropertyDescriptor nestedDesc = nestedProps[j];
  //Add to the top most PropertyDescriptor Collection
  //CANNOT ADD SINCE NOT IMPLEMENTED
  props.Add(nestedDesc);


 }

 }
 return props;
}
}

Thanks in advance
Viktor

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to