PC Review


Reply
Thread Tools Rate Thread

Databinding with Nested Objects

 
 
Victor Jones
Guest
Posts: n/a
 
      30th Oct 2003
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
{
 
Reply With Quote
 
 
 
 
Thomas Tomiczek \(MVP\)
Guest
Posts: n/a
 
      30th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:%23U$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Victor Jones
Guest
Posts: n/a
 
      30th Oct 2003
Thanks for the suggestion. Doesn't hurt to get different opinions on
different newsgroups


"Thomas Tomiczek (MVP)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%23U$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Thomas Tomiczek \(MVP\)
Guest
Posts: n/a
 
      30th Oct 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for the suggestion. Doesn't hurt to get different opinions on
> different newsgroups
>
>
> "Thomas Tomiczek (MVP)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%23U$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs Microsoft ASP .NET 0 26th Sep 2007 12:54 AM
Databinding Bible (REPOST FROM m.p.d.f.WindowsForms.Databinding) a Microsoft ADO .NET 1 16th Jul 2004 03:26 AM
Databinding: Objects within Objects as Properties Aaron Moore via .NET 247 Microsoft Dot NET Framework Forms 0 10th Jun 2004 03:48 PM
Problems with Databinding, with nested objects mdan Microsoft Dot NET Framework 0 13th Nov 2003 07:30 PM
Problems with Databinding, with nested objects properties Maximiliano Microsoft Dot NET Framework Forms 0 2nd Nov 2003 06:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:39 AM.