码迷,mamicode.com
首页 > 其他好文 > 详细

INotifyPropertyChanged接口应用示例

时间:2018-12-10 15:40:51      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:表数   tag   div   orm   val   bind   ring   示例   tom   

使用INotifyPropertyChanged接口,当表数据更改时发生更新

public class Customer :INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged=delegate{};
    private string _customerName;
    private string _phoneNumber;
    public string CustomerName
    {
        get{return _customerName;}
        set
        {
            if(_customerName!=value)
            {
                    _customerName=value;
                    PropertyChanged(this,new PropertyChanged("CustomerName"));
            }
        }
    }       
    public string PhoneNumber
    {
        get{return _phoneNumber;}
        set
        {
            if(_phoneNumber!=value)
            {
                    _phoneNumber=value;
                    PropertyChanged(this,new PropertyChanged("PhoneNumber"));
            }
        }
    } 
}
/*******************************************************/
public class Form
{
    private BindingList<Customer> customers= new BindingList<Customer>();
}
public void AddData()
{
    customers.Add(new Customer() {Customer="zs",PhoneNumber="123"});
    customers.Add(new Customer(){Customer="ls",PhoneNumber="456"});
    this.dataGridViewe1.DataSource = customers;
}
public void UpdateData()
{
    customers[0].CustomerName="ww";
}

 

INotifyPropertyChanged接口应用示例

标签:表数   tag   div   orm   val   bind   ring   示例   tom   

原文地址:https://www.cnblogs.com/clgis/p/10096310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!