364,033 Members | 4781 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Data binding to another object

Sam Martin
P: n/a
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


Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


Nicholas Paldino [.NET/C# MVP]
P: n/a
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.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Sam Martin" <sambomartin@yahoo.co.uk> wrote in message
news:e$1I5aKzEHA.352@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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
>[/color]


Nov 16 '05 #2

Post your reply

Help answer this question



Didn't find the answer to your C# / C Sharp question?

You can also browse similar questions: C# / C Sharp