all groups > dotnet windows forms databinding > june 2005 >
You're in the

dotnet windows forms databinding

group:

Updating a control when object changes.


Updating a control when object changes. jtwomley
6/8/2005 6:19:04 PM
dotnet windows forms databinding:
I have a control that has a databinding attached to it like so.

txtName.DataBindings.Add("Text", nameClass, "Name");
This works great the Name property from nameClass is populated in the
txtName field

Now I have btnOne. In the click event of btnOne I call

nameClass.Name = "SMITH";

At this point why does the txtName not update?
I am looking for an answer other than adding the NameChanged EventHandler in
the nameClass object.

I am working in .net 2.0

RE: Updating a control when object changes. TToni
7/13/2005 12:26:03 AM
Well, your question is: Why does it not update?

The answer is: It cannot, because it does not know when the objects property
changes. How should it know? When you set the objects property you execute a
piece of code you wrote by yourself. So no code gets executed that could
notify the BindingManager (and thus the TextBox) of this change. That's why
you need that ChangedEvent. The BindingManager looks through Reflection for a
Changed-Event with the right name, but if it does not find one, there's not
much it can do (except changing the code of your Property-function, or
polling every few microseconds all bound properties of your class, but you
really would not like the implications of these methods).

It works the other way round, precisely because the TextBox *has* a
TextChanged-Event, so the BindingManager can hook up to it and propagate the
change.

TToni

[quoted text, click to view]
AddThis Social Bookmark Button