PropertyChanged event firing twice?PropertyChanged event firing twice?
Old forum URL: forums.lhotka.net/forums/t/6177.aspx
Curtmantle posted on Friday, January 16, 2009
I am trapping the PropertyChanged event of my business classes on my WinForms and have noticed that the event handler is called twice when a property is changed.
eg:
BusinessClass bo = BusinessClass.NewBusinessClass();
bo.PropertyChanged += PropertyChangedEventHandler(Base_PropertyChanged);
private void Base_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//will display twice when a BO property is changed
MessageBox.Show("Huh?");
}
The only thing that springs to mind is that I am storing the Business Object as a member variable, and setting the BindingSource's datasource to that member variable, but I don't really see why that should make a difference as it's a reference.
Is there a technical reason for this that I am unaware of? The business class is only firing the event once, so it appears to be Binding related. I am using CSLA 3.0.4.0.
Thanks
Curtmantle replied on Friday, January 16, 2009
I have found the reason for this, and I'm happy to say it's not a problem with CSLA, but the idiot who programmed the form used as a base for all the forms in my app. That idiot being me!
I was inadvertently setting the PropertyChanged handler twice: ie - bo.PropertyChanged += etc...
Doh!
Copyright (c) Marimer LLC