HighTechTalks DotNet Forums  

Binding to a Coarse Grained Object

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss Binding to a Coarse Grained Object in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
news.microsoft.com
 
Posts: n/a

Default Binding to a Coarse Grained Object - 11-02-2007 , 12:16 AM






I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Bill



Reply With Quote
  #2  
Old   
Jack Jackson
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-02-2007 , 08:08 AM






On Fri, 2 Nov 2007 02:16:30 -0400, "news.microsoft.com"
<billgower (AT) charter (DOT) net> wrote:

Quote:
I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?
Add a CustomerId Property to Invoice that returns Customer.CustomerId.


Reply With Quote
  #3  
Old   
BillG
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-02-2007 , 08:21 AM



So for every field in customer that I need to access and in other classes
that are composites I need to set properties up in Invoice?

Bill

"Jack Jackson" <jacknospam (AT) pebbleridge (DOT) com> wrote

Quote:
On Fri, 2 Nov 2007 02:16:30 -0400, "news.microsoft.com"
billgower (AT) charter (DOT) net> wrote:

I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied
to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Add a CustomerId Property to Invoice that returns Customer.CustomerId.


Reply With Quote
  #4  
Old   
Jack Jackson
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-02-2007 , 11:48 AM



I believe so. I don't think you can bind to anything except
properties of the object.

On Fri, 2 Nov 2007 10:21:35 -0400, "BillG" <billgower (AT) charter (DOT) net>
wrote:

Quote:
So for every field in customer that I need to access and in other classes
that are composites I need to set properties up in Invoice?

Bill

"Jack Jackson" <jacknospam (AT) pebbleridge (DOT) com> wrote in message
news:npbmi39kj7uiso93qj0ob7ougb803b11ok (AT) 4ax (DOT) com...
On Fri, 2 Nov 2007 02:16:30 -0400, "news.microsoft.com"
billgower (AT) charter (DOT) net> wrote:

I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied
to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Add a CustomerId Property to Invoice that returns Customer.CustomerId.

Reply With Quote
  #5  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-04-2007 , 12:30 PM



On Fri, 02 Nov 2007 15:08:51 +0100, Jack Jackson <jacknospam (AT) pebbleridge (DOT) com> wrote:

Quote:
On Fri, 2 Nov 2007 02:16:30 -0400, "news.microsoft.com"
billgower (AT) charter (DOT) net> wrote:

I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Add a CustomerId Property to Invoice that returns Customer.CustomerId.

This is a very bad solution. You can easily refer to child objects in a BindingSource
(see solution elsewhere in this thread)

--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #6  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-04-2007 , 12:31 PM



Hi Bill,

Just refer to the property like you would in code.

Invoice invoice = new Invoice();
BindingSource source = new BindingSource(invoice, "");

// Bind to the CustomerName property of the CustomerName object in the Invoice object
textBox1.DataBindings.Add("Text", source, "Customer.CustomerName");



On Fri, 02 Nov 2007 07:16:30 +0100, news.microsoft.com <billgower (AT) charter (DOT) net> wrote:

Quote:
I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm,I
bind the controls on the form to a binding source InvoiceBS which is tied to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Bill





--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #7  
Old   
BillG
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-05-2007 , 03:19 PM



So can this be done only in code or can it be done in the designer property
window for the target object?

Bill

"Morten Wennevik [C# MVP]" <MortenWennevik (AT) hotmail (DOT) com> wrote

Hi Bill,

Just refer to the property like you would in code.

Invoice invoice = new Invoice();
BindingSource source = new BindingSource(invoice, "");

// Bind to the CustomerName property of the CustomerName object in the
Invoice object
textBox1.DataBindings.Add("Text", source, "Customer.CustomerName");



On Fri, 02 Nov 2007 07:16:30 +0100, news.microsoft.com
<billgower (AT) charter (DOT) net> wrote:

Quote:
I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied
to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Bill





--
Happy coding!
Morten Wennevik [C# MVP]



Reply With Quote
  #8  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: Binding to a Coarse Grained Object - 11-06-2007 , 09:45 AM




Well, partly. It you set Invoice as a DataSource, you should see Customer as a node under Invoice creating the DataBinding in the designer. You won't see any members of Customer, but you can edit the binding in thedesigner and add ".CustomerName". I much prefer doing this in code though.


On Mon, 05 Nov 2007 22:19:47 +0100, BillG <billgower (AT) charter (DOT) net> wrote:

Quote:
So can this be done only in code or can it be done in the designer property
window for the target object?

Bill

"Morten Wennevik [C# MVP]" <MortenWennevik (AT) hotmail (DOT) com> wrote in message
newsp.t095rhzwdj93y5 (AT) ubuan (DOT) ..
Hi Bill,

Just refer to the property like you would in code.

Invoice invoice = new Invoice();
BindingSource source = new BindingSource(invoice, "");

// Bind to the CustomerName property of the CustomerName object in the
Invoice object
textBox1.DataBindings.Add("Text", source, "Customer.CustomerName");



On Fri, 02 Nov 2007 07:16:30 +0100, news.microsoft.com
billgower (AT) charter (DOT) net> wrote:

I have an object called Invoice which has as one of its members, an object
called customer which is of type Customer. Class Customer has properties
such as CustomerId, CustomerName, etc. In my form, InvoiceDetailForm, I
bind the controls on the form to a binding source InvoiceBS which is tied
to
the Invoice object. How do I bind a control on the form to
Invoice.Customer.CustomerId using the designer?

Bill








--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.