Nested objects and INotifyPropertyChanged

G

Guest

Hi,

I've created a Person-Object which implemts INotifyPropertyChanged. This
Person-Object contains an Address-Object which implements
INotifyPropertyChanged too.

Then I create a BindingList<Person> which is the DataSource for my
BindingSource. I created some TextBoxes bound to this BindingSource like this:

Binding b = new Binding("Text", bindingSource, "Name");
Binding b = new Binding("Text", bindingSource, "Address.Street");

Updating the Name-Property works fine and I get a ListChanged-Event but when
I update the Street-Property I never get a ListChanged-Event.

What am I doing wrong?


Betina
 
G

Guest

Hi Betina,
the problem you are having is because you are databinding to the Person
object, because you have a list of peolpe at the underlying datasource. What
you need to do is make sure that when the Address object raises the
PRopertyChanged event that the Person class that contains the event captures
the event and also raises a PropertyChanged event, then both the person and
addres controls should update.

Hope that helps
Mark Dawson
http://www.markdawson.org
 
G

Guest

Hi Mark,

is this the only way to make it work? I load the private member of the
objects through reflection and there's no easy way to capture events.

Is there any possibilty to capture this events in the bindinglist? I'm
working with a derived class and I think changing this class would be a more
general solution.


Thanks for your answer.


Betina
 
G

Guest

Hi Betina,
I am not sure I am exactly following you, if you can do the folowing:

Then you must have access to the bindingsource and the list of people so you
can write some code like:

foreach(Person p in people)
{
// wire up p.Address.PropertyChanged to some event handler in P
}

Do you not have access to these things?
 
G

Guest

Hi Mark,

yes, I have access to these things and I think it should be possible. I read
about the IRaiseItemChangedEvents and I will give it a try.

Thank you.

Betina
 

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