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
        }
    }


  • 相关阅读:
    接口测试第一天:使用requests依赖库发送http请求
    接口测试第一天:使用unittest作为集成测试框架
    python_basic
    观看《黑客帝国》有感
    采集数据注意事项
    操作系统_第二章_进程与线程
    第一章_操作系统概论
    感言&2
    计算机信息安全技术_课后习题总结
    预处理
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1863893.html
Copyright © 2011-2022 走看看