|
-
October 17th, 2016, 03:01 PM
#1
INotifyPropertyChanged why it does not to inform and does not need eventhandlerproce
This code is from a Winform VS2012, works well.
But normally, If I want to use an event of a datagriedview or listview, I have to inform about the event and than the eventhandle procedure is expected, like within the first example.
But if it comes to INotifyPropertyChanged, none of it is needed. I cant see, neither understand why. I searchd around, even considering that INotify is an interface, but finally havnt found any explication.
First example has a code from Winform(Load event, button and datagridview.doubleclickevent)
Second example is class Customer, with PropertyChangedEventHandler
Code:
public partial class Form1 : Form
{
private BindingList<Customer> myBind = null;
private Customer myCust= null;
public Form1()
{
myBind = new BindingList<Customer>();
myCust = new Customer();
myCust = myBind.AddNew();
InitializeComponent();
this.dataGridView1.CellDoubleClick += dataGridView1_CellDoubleClick;
}
private void dataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e)
{
//[...]
}
private void button1_Click(object sender, EventArgs e)
{
myCust.Company = "new Company";
myCust.PosteCode = 1111456;
}
private void Form1_Load(object sender, EventArgs e)
{
myCust.Company = "AnyCompany";
myCust.PosteCode = 123446;
this.txtCompany.DataBindings.Add("Text", myBind, "Company");
this.txtPostCode.DataBindings.Add("Text", myBind, "PosteCode");
}
}
// Second Example class Customer with PropertyChangedEventHandler
Code:
public class Customer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string mCompany;
private int mPostCode;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
public string Company
{
get { return mCompany; }
set
{
mCompany = value;
OnPropertyChanged(new PropertyChangedEventArgs("Company"));
}
}
public int PosteCode
{
get { return mPostCode; }
set
{
mPostCode = value;
OnPropertyChanged(new PropertyChangedEventArgs("PosteCode"));
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|