473,887 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

INotifyProperty Changed Bug ?

Hi,

I'm not sure if i'm misunderstandin g how INotifyProperty Changed should
work but it's not working as I expected.

I have a sample program with a very simple 'Customer' class with three
properties code, name & address. All these are bound to a form via a
BindingSource and fire the PropertyChanged event when the property is
modified.

I change one of these properties in code and find that all of the
properties are fetched and rebound to the form. Is this correct ?
What's the point of specifying a property name in the
PropertyChanged EventArgs if all the controls are rebound anyway.

Any help would be much appreciated

John

If it's any help my code is below

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace NotifyChange
{
public partial class Form1 : Form
{
private Customer _customer;

public Form1()
{
InitializeCompo nent();
_customer = new Customer();
_customer.Code = "G001";
_customer.Name = "Greenwood Enterpises Ltd";
_customer.Addre ss = "128 Smithey Road";
customerBinding Source.DataSour ce = _customer;
}

private void button1_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Code --");

_customer.Code = "F001";

Console.WriteLi ne("-- Change Code -->");
}

private void button2_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Name --");

_customer.Name = "Fletcher Business Services Ltd";

Console.WriteLi ne("-- Change Name -->");
}

}

public class Customer : INotifyProperty Changed
{

private string _code = "";
private string _name = "";
private string _address = "";

public string Code
{
get
{
Console.WriteLi ne("Got 'Code' at {0}", DateTime.Now);
return _code;
}
set
{
if (_code != value)
{
_code = value;

NotifyPropertyC hanged(" Code");
}
}
}

public string Name
{
get
{
Console.WriteLi ne("Got 'Name' at {0}", DateTime.Now);
return _name;
}
set
{
if (_name != value)
{
_name = value;

NotifyPropertyC hanged("Name");
}
}
}

public string Address
{
get
{
Console.WriteLi ne("Got 'Address' at {0}",
DateTime.Now);
return _address;
}
set
{
_address = value;
}
}

private void NotifyPropertyC hanged(string Name)
{

if (PropertyChange d != null)
{
PropertyChanged (this, new
PropertyChanged EventArgs(Name) );
}
}
#region INotifyProperty Changed Members

public event PropertyChanged EventHandler PropertyChanged ;

#endregion
}
Jan 18 '07 #1
2 2282
I would think that propertychanged means that it already happened, while
propertychangin g gives you the opportunity to stop it.

take a look at how formclosing and formclosed behave.

"John Greenwood" <jo************ @bhpit.co.ukwro te in message
news:2d******** *************** *********@4ax.c om...
Hi,

I'm not sure if i'm misunderstandin g how INotifyProperty Changed should
work but it's not working as I expected.

I have a sample program with a very simple 'Customer' class with three
properties code, name & address. All these are bound to a form via a
BindingSource and fire the PropertyChanged event when the property is
modified.

I change one of these properties in code and find that all of the
properties are fetched and rebound to the form. Is this correct ?
What's the point of specifying a property name in the
PropertyChanged EventArgs if all the controls are rebound anyway.

Any help would be much appreciated

John

If it's any help my code is below

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace NotifyChange
{
public partial class Form1 : Form
{
private Customer _customer;

public Form1()
{
InitializeCompo nent();
_customer = new Customer();
_customer.Code = "G001";
_customer.Name = "Greenwood Enterpises Ltd";
_customer.Addre ss = "128 Smithey Road";
customerBinding Source.DataSour ce = _customer;
}

private void button1_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Code --");

_customer.Code = "F001";

Console.WriteLi ne("-- Change Code -->");
}

private void button2_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Name --");

_customer.Name = "Fletcher Business Services Ltd";

Console.WriteLi ne("-- Change Name -->");
}

}

public class Customer : INotifyProperty Changed
{

private string _code = "";
private string _name = "";
private string _address = "";

public string Code
{
get
{
Console.WriteLi ne("Got 'Code' at {0}", DateTime.Now);
return _code;
}
set
{
if (_code != value)
{
_code = value;

NotifyPropertyC hanged(" Code");
}
}
}

public string Name
{
get
{
Console.WriteLi ne("Got 'Name' at {0}", DateTime.Now);
return _name;
}
set
{
if (_name != value)
{
_name = value;

NotifyPropertyC hanged("Name");
}
}
}

public string Address
{
get
{
Console.WriteLi ne("Got 'Address' at {0}",
DateTime.Now);
return _address;
}
set
{
_address = value;
}
}

private void NotifyPropertyC hanged(string Name)
{

if (PropertyChange d != null)
{
PropertyChanged (this, new
PropertyChanged EventArgs(Name) );
}
}
#region INotifyProperty Changed Members

public event PropertyChanged EventHandler PropertyChanged ;

#endregion
}

Jan 18 '07 #2
Hi,
Thanks for the response, but the INotifyProperty Changed is an
interface, providing your own classes with the abilbity to trigger an
event telling the form to rebind a property. Problem is, regardless of
the property specified in the event, all the forms controls are
rebound.

On Thu, 18 Jan 2007 09:34:31 -0600, "AMDRIT" <am****@hotmail .com>
wrote:
>I would think that propertychanged means that it already happened, while
propertychangi ng gives you the opportunity to stop it.

take a look at how formclosing and formclosed behave.

"John Greenwood" <jo************ @bhpit.co.ukwro te in message
news:2d******* *************** **********@4ax. com...
>Hi,

I'm not sure if i'm misunderstandin g how INotifyProperty Changed should
work but it's not working as I expected.

I have a sample program with a very simple 'Customer' class with three
properties code, name & address. All these are bound to a form via a
BindingSourc e and fire the PropertyChanged event when the property is
modified.

I change one of these properties in code and find that all of the
properties are fetched and rebound to the form. Is this correct ?
What's the point of specifying a property name in the
PropertyChange dEventArgs if all the controls are rebound anyway.

Any help would be much appreciated

John

If it's any help my code is below

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace NotifyChange
{
public partial class Form1 : Form
{
private Customer _customer;

public Form1()
{
InitializeCompo nent();
_customer = new Customer();
_customer.Code = "G001";
_customer.Name = "Greenwood Enterpises Ltd";
_customer.Addre ss = "128 Smithey Road";
customerBinding Source.DataSour ce = _customer;
}

private void button1_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Code --");

_customer.Code = "F001";

Console.WriteLi ne("-- Change Code -->");
}

private void button2_Click(o bject sender, EventArgs e)
{
Console.WriteLi ne("<-- Change Name --");

_customer.Name = "Fletcher Business Services Ltd";

Console.WriteLi ne("-- Change Name -->");
}

}

public class Customer : INotifyProperty Changed
{

private string _code = "";
private string _name = "";
private string _address = "";

public string Code
{
get
{
Console.WriteLi ne("Got 'Code' at {0}", DateTime.Now);
return _code;
}
set
{
if (_code != value)
{
_code = value;

NotifyPropertyC hanged(" Code");
}
}
}

public string Name
{
get
{
Console.WriteLi ne("Got 'Name' at {0}", DateTime.Now);
return _name;
}
set
{
if (_name != value)
{
_name = value;

NotifyPropertyC hanged("Name");
}
}
}

public string Address
{
get
{
Console.WriteLi ne("Got 'Address' at {0}",
DateTime.Now );
return _address;
}
set
{
_address = value;
}
}

private void NotifyPropertyC hanged(string Name)
{

if (PropertyChange d != null)
{
PropertyChanged (this, new
PropertyChange dEventArgs(Name ));
}
}
#region INotifyProperty Changed Members

public event PropertyChanged EventHandler PropertyChanged ;

#endregion
}
Jan 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
1643
by: gwolinsky | last post by:
I originally posted this in the WindowsForms group but that may not have been the best place to post it. So, I am reposting here. -------------------------------------- I am trying to implement the new INotifyPropertyChanged interface in my custom business object. The problem I'm having is with the inheritance model. I have a base object called "Person". The object "Employee" inherits
4
5868
by: Betina | last post by:
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");
1
2133
by: Hardeek Thakkar | last post by:
Dear friends, In my current project I am using the CustomCollections with the help of BindingList<Tgeneric class to store the database records instead using DataSet objects as offline database identities. Now I do have a large number of property classes each having a large number of properties in it. I want to implement the INotifyPropertyChanged interface in every
1
3377
by: Gokul | last post by:
Hi, I'm using indexed properties in an object which acts as the binding source. How can I implement INotifyPropertyChanged for that object so that when the indexed property is updated, binding target is updated? To be more specific please find the code below.. public class ClassA : INotifyPropertyChanged
0
3180
by: Gerrit | last post by:
Hello, On http://msdn2.microsoft.com/en-us/library/ms184414.aspx is an example of the implementation of INotifyPropertyChanged Interface. I work with the C# example. I have tried this sample, and it works, but I have a problem with it. When I push the button, the first CompanyName is changed in Tailspin Toys directly.
0
897
by: liruiyt | last post by:
This time I found a thorny problem, for I'm a new. When I binding an object to the page in WPF, and the object has a Property of XmlDocument Datatype. And I bind an element of the Property(XmlDocument) to a TextBox, when I change the TextBox's content, how I can trigger the Property' set and trigger the PropertyHasChanged EventHandler. Maybe, means this, when I just changed an element of an object's property that is a XmlDocument...
5
4000
by: jehugaleahsa | last post by:
Hello: I have a mapping class that can take generic data objects and locate/ add/remove/update DataRows in a DataTable. I associate them using attributes: TableAttribute and ColumnAttribute. I use reflection to move the data between the data object and the DataTable. I would like to make this extremely easy for my Forms developers. I would like calling AddNew() to call mapper.AddDataRow(dataObject).
2
7223
by: Dinsdale | last post by:
We have created a object library that implements the INotifyPropertyChanged.PropertyChanged to bubble changes up to higher level classes. For instance, we have a person class that can have relationships with other persons. If there is a change in the relationship (i.e. status, type etc) then we want the PropertyChanged event to fire and notify the top level Person object of that change. The PropertyChanged event is implemented as follows:...
2
2938
by: nelmr | last post by:
Okay say we have a class that implements INotifyPropertyChanged and a property that has code in the setter to raise the PropertyChanged event. On the GUI side we have a text box with the code: txtFirst.DataBindings.Add("Text", p, "FirstName", True) Where p is a Person object and FirstName is the property that raises the PropertyChanged event. It works perfectly when I programmatically change the object's property or using the application,...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10770
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10430
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9593
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7988
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.