首页 > 其他 > 详细

INotifyPropertyChanged接口应用示例

时间:2018-12-10 14:56:12      阅读:153      评论:0      收藏:0      [点我收藏+]

使用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接口应用示例

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!