Data binding to another object

S

Sam Martin

Hi all,

I've sorted out binding to and from my business entities, however....
Pulling data from the business entities is easy using the
<control>.DataBindings.Add(..) method. These bindings take care if
themselves from UI.
Pushing data from these objects was a bit more problematical, but discovered
that the data binder listens for <PropName>Changed events, and that it only
takes one property/event to trigger an update for the bound data object. To
create a generic "push" method in my business entities, I declared a
property in my base entity class and a method (.e.g. UpdateBound()) that
sets the common property (i.e. Entity.Data) to be Entity.Data (itself) - and
in the Data property, on the set() method i fire a DataChanged event which
the data binder handles and refreshes the bound controls for the data
object.
As long as the property in the base entity is bound to a control's property
it work fine.

This is my problem, in some cases I will need to manage mutiple business
entities from within a form so I need to know if it's possible to create
like a custom bindings for my business entities. for example bind property X
of object A to property Y of object B ?

TIA

Sam
 
N

Nicholas Paldino [.NET/C# MVP]

Sam,

Unfortinately, there is nothing that does that in .NET right now. I
recommend having a controller class, which has references to the two
objects, and then having it coordinate the setting of the property when the
events are fired (you could use reflection in the same way).

You ^might^ be able to get away with extending BindingsCollection, but I
don't know how much plumbing it will provide. If it provides enough, you
might be able to use it on your objects.

Hope this helps.
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top