PC Review


Reply
Thread Tools Rate Thread

Deep object binding

 
 
Benny
Guest
Posts: n/a
 
      29th Aug 2006
I just cant find a good explanation on how to "deep bind" objects, so
im hoping someone can help. I have an object that contains another
object, for example: Book has a title, pagecount, and an Author. The
title and pagecount are system objects but Author is a type i have
definied. I need to know how i could bind the Author.FirstName
property (for example) to the same grid like any property of the
containing object. another example:

datagrid1.DataSource = Books1;
....
datacolumnstyle1.MappingName = "Title";
....
datacolumnstyle2.MappingName = "Author.FirstName";
....

There are a couple articles out there for doing this but there is no
explanation on how to customize the code and im brand new to
reflection. Any help would be greatly appreciated.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VWhpaGFKYXg=?=
Guest
Posts: n/a
 
      29th Aug 2006
That one is simple, actually binding the object is slightly more tricky (you
need drop down lists and binding to "SelectedItem") but this just binding the
odd property (e.g. author name) requires a little composition like so.

Try this.

class MyBookWrapper()
{
private Book book;

MyBookWrapper(Book book)
{
this.book = book;
}

public string AuthorName
{
get{return book.Author.Name;}
set{book.Author.Name = value;}
}
}

HTH.

"Benny" wrote:

> I just cant find a good explanation on how to "deep bind" objects, so
> im hoping someone can help. I have an object that contains another
> object, for example: Book has a title, pagecount, and an Author. The
> title and pagecount are system objects but Author is a type i have
> definied. I need to know how i could bind the Author.FirstName
> property (for example) to the same grid like any property of the
> containing object. another example:
>
> datagrid1.DataSource = Books1;
> ....
> datacolumnstyle1.MappingName = "Title";
> ....
> datacolumnstyle2.MappingName = "Author.FirstName";
> ....
>
> There are a couple articles out there for doing this but there is no
> explanation on how to customize the code and im brand new to
> reflection. Any help would be greatly appreciated.
>
>

 
Reply With Quote
 
=?Utf-8?B?VWhpaGFKYXg=?=
Guest
Posts: n/a
 
      29th Aug 2006
I should have added that you bind the wrapper to the control, instead of the
original object.

"UhihaJax" wrote:

> That one is simple, actually binding the object is slightly more tricky (you
> need drop down lists and binding to "SelectedItem") but this just binding the
> odd property (e.g. author name) requires a little composition like so.
>
> Try this.
>
> class MyBookWrapper()
> {
> private Book book;
>
> MyBookWrapper(Book book)
> {
> this.book = book;
> }
>
> public string AuthorName
> {
> get{return book.Author.Name;}
> set{book.Author.Name = value;}
> }
> }
>
> HTH.
>
> "Benny" wrote:
>
> > I just cant find a good explanation on how to "deep bind" objects, so
> > im hoping someone can help. I have an object that contains another
> > object, for example: Book has a title, pagecount, and an Author. The
> > title and pagecount are system objects but Author is a type i have
> > definied. I need to know how i could bind the Author.FirstName
> > property (for example) to the same grid like any property of the
> > containing object. another example:
> >
> > datagrid1.DataSource = Books1;
> > ....
> > datacolumnstyle1.MappingName = "Title";
> > ....
> > datacolumnstyle2.MappingName = "Author.FirstName";
> > ....
> >
> > There are a couple articles out there for doing this but there is no
> > explanation on how to customize the code and im brand new to
> > reflection. Any help would be greatly appreciated.
> >
> >

 
Reply With Quote
 
John Vottero
Guest
Posts: n/a
 
      29th Aug 2006
"Benny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I just cant find a good explanation on how to "deep bind" objects, so
> im hoping someone can help. I have an object that contains another
> object, for example: Book has a title, pagecount, and an Author. The
> title and pagecount are system objects but Author is a type i have
> definied. I need to know how i could bind the Author.FirstName
> property (for example) to the same grid like any property of the
> containing object. another example:
>
> datagrid1.DataSource = Books1;
> ...
> datacolumnstyle1.MappingName = "Title";
> ...
> datacolumnstyle2.MappingName = "Author.FirstName";
> ...
>
> There are a couple articles out there for doing this but there is no
> explanation on how to customize the code and im brand new to
> reflection. Any help would be greatly appreciated.


Are you saying that "Author.FirstName" doesn't work? I don't use datagrids
but, we do deep binding to other controls.

Here's how you would bind the Authors first name to a text control:

controlName.DataBindings.Add("Text", bindingSource,
"Author.FirstName");

In our code, "bindingSource" would be a BookCollection which contains a
collection of Books.


 
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
Binding TextBox.Text to property in nested (multi levels) object withbindingsource, Error if grandchild object is NULL Efy Microsoft Dot NET 0 14th Oct 2009 11:06 AM
Deep copy between two different object. AllenGnr@gmail.com Microsoft C# .NET 6 4th Apr 2006 02:50 AM
Re: Object Relational Mapper with deep copy ability? Josh Microsoft ADO .NET 2 25th Nov 2005 10:12 PM
Re: How deep should a deep copy go? / Is an object that contains value type still a reference type? ahaupt@gmail.com Microsoft C# .NET 0 31st Aug 2005 02:29 PM
Re: How deep should a deep copy go? / Is an object that contains value type still a reference type? Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 0 30th Aug 2005 04:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.