Databinding with Nested Objects

Discussion in 'Microsoft Dot NET Framework Forms' started by Victor Jones, Oct 30, 2003.

  1. Victor Jones

    Victor Jones Guest

    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
    {
     
    Victor Jones, Oct 30, 2003
    #1
    1. Advertisements

  2. You really love asking the same question separatly in two newsgroups

    Bear with me when I say I dont like ansering them in two newsgroups. I
    answered to your post in the databinding newsgroup.

    Thomas Tomiczek
    THONA Software & Consulting Ltd.
    (Microsoft MVP C#/:NET)

    "Victor Jones" <> wrote in message
    news:%23U$...
    > 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;
    > 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
    >
    >
     
    Thomas Tomiczek \(MVP\), Oct 30, 2003
    #2
    1. Advertisements

  3. Victor Jones

    Victor Jones Guest

    Thanks for the suggestion. Doesn't hurt to get different opinions on
    different newsgroups ;)


    "Thomas Tomiczek (MVP)" <> wrote in message
    news:...
    > You really love asking the same question separatly in two newsgroups
    >
    > Bear with me when I say I dont like ansering them in two newsgroups. I
    > answered to your post in the databinding newsgroup.
    >
    > Thomas Tomiczek
    > THONA Software & Consulting Ltd.
    > (Microsoft MVP C#/:NET)
    >
    > "Victor Jones" <> wrote in message
    > news:%23U$...
    > > 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;
    > > 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
    > >
    > >

    >
    >
     
    Victor Jones, Oct 30, 2003
    #3
  4. Does not get hurt, no.

    But it shows you dont care for the work other do and you are not a friendly
    person.

    Why did you not CROSSPOST as netiquette asks for?

    Frankly, dont you know how to use a newsreader?

    You multiposted, and this is frowned upon.

    Thomas Tomiczek

    "Victor Jones" <> wrote in message
    news:...
    > Thanks for the suggestion. Doesn't hurt to get different opinions on
    > different newsgroups ;)
    >
    >
    > "Thomas Tomiczek (MVP)" <> wrote in message
    > news:...
    > > You really love asking the same question separatly in two newsgroups
    > >
    > > Bear with me when I say I dont like ansering them in two newsgroups. I
    > > answered to your post in the databinding newsgroup.
    > >
    > > Thomas Tomiczek
    > > THONA Software & Consulting Ltd.
    > > (Microsoft MVP C#/:NET)
    > >
    > > "Victor Jones" <> wrote in message
    > > news:%23U$...
    > > > 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;
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Thomas Tomiczek \(MVP\), Oct 30, 2003
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. A. Woelfer

    simple Databinding

    A. Woelfer, Jul 4, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    619
    A. Woelfer
    Jul 4, 2003
  2. James

    DataGrid, DataSet, databinding across threads fails?

    James, Jul 7, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    715
    James
    Jul 7, 2003
  3. Matt

    databinding lose focus

    Matt, Jul 9, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    638
  4. Iulian Ionescu

    Designer of nested objects question.

    Iulian Ionescu, Oct 14, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    254
    Iulian Ionescu
    Oct 14, 2003
  5. Maximiliano

    Problems with Databinding, with nested objects properties

    Maximiliano, Nov 2, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    255
    Maximiliano
    Nov 2, 2003
  6. Sandeep Arora via .NET 247

    Undo/Redo - Business Objects, User Interface and DataBinding

    Sandeep Arora via .NET 247, May 8, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    689
    Sandeep Arora via .NET 247
    May 8, 2004
  7. Aaron Moore via .NET 247

    Databinding: Objects within Objects as Properties

    Aaron Moore via .NET 247, Jun 10, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    318
    Aaron Moore via .NET 247
    Jun 10, 2004
  8. BobRoyAce

    Best practice for saving objects owned by objects

    BobRoyAce, Mar 5, 2008, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    418
    Mr. Arnold
    Mar 5, 2008
Loading...