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


  • 相关阅读:
    drag element
    时间会改变一切
    Windows下MySQL的my.ini文件字符集测试(二)
    Windows下MySQL的my.ini文件字符集测试
    SQL Server和MySQL主外键写法对比
    SQL Server外键约束
    [SQL Server]重命名数据库【转】
    SQL Server 2008 R2链接MySQL 5.6
    空值的日期类型和update 中的null
    删除数据库中所有表
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1863893.html
Copyright © 2011-2022 走看看