zoukankan      html  css  js  c++  java
  • INotifyPropertyChanged

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
        
    public partial class Form1 : Form
        {
            
    public Form1()
            {
                InitializeComponent();
            }

            
    private void button1_Click(object sender, EventArgs e)
            {
                BindingList
    <DemoCustomer> customerList = bindingSource1.DataSource as BindingList<DemoCustomer>;

                customerList[
    0].Name = "aa";
                bindingSource1.ResetItem(
    0);
            }

            
    private void Form1_Load(object sender, EventArgs e)
            {
                BindingList
    <DemoCustomer> customer = new BindingList<DemoCustomer>();
                customer.Add(DemoCustomer.CreateCustomer());
                customer.Add(DemoCustomer.CreateCustomer());
                customer.Add(DemoCustomer.CreateCustomer());

                bindingSource1.DataSource 
    = customer;
                dataGridView1.DataSource 
    = bindingSource1;
            }
        }
        
    public class DemoCustomer : INotifyPropertyChanged
        {
            
    private Guid idValue = Guid.NewGuid();
            
    private string name = string.Empty;

            
    public string Name
            {
                
    get { return name; }
                
    set {
                    
    if (value != this.name)
                    {
                        name 
    = value;

                        NotifyPropertyChanged(
    "customer");
                    }
                }
            }
            
    private string phone = string.Empty;

            
    public string Phone
            {
                
    get { return phone; }
                
    set {
                    
    if (value != this.phone)
                    {
                        phone 
    = value;
                        NotifyPropertyChanged(
    "phone");
                    }
                }
            }

            
    private void NotifyPropertyChanged(string info)
            {
                
    if (PropertyChanged != null)
                {
                    PropertyChanged(
    thisnew PropertyChangedEventArgs(info));
                }
            }
            
    //单例
            private DemoCustomer()
            {
                name 
    = "customer";
                phone 
    = "(555)1234567";
            }
            
    public static DemoCustomer CreateCustomer()
            {
                
    return new DemoCustomer();
            }

            
    public Guid Id
            {
                
    get
                {
                    
    return this.idValue;
                }
            }
            
    #region INotifyPropertyChanged 成员

            
    public event PropertyChangedEventHandler PropertyChanged;

            
    #endregion
        }
    }


  • 相关阅读:
    动态规划3-最长公共子序列问题
    动态规划2-最大子段和
    动态规划1- 矩阵取数
    javac编译提示错误需要为 class、interface 或 enum
    [core python programming]chapter 7 programming MS office
    ubuntu apache nginx 启动 关闭
    ubuntu 安装 hustoj
    TCP报文段的首部格式
    守护进程
    会话session
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1863893.html
Copyright © 2011-2022 走看看