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


  • 相关阅读:
    公司官网ucenter搬家注意问题
    PHP中获取CHECKBOX提交的内容及checkbox全选
    js注册验证
    c# 相对路径的一些文献
    C# 读取xml中的配置信息,并加入到combobox或者其他中(winform)
    java 路径问题,防止再忘掉
    Mastering the Java CLASSPATH
    ps 制作背景透明 图片
    c# 双缓冲 技术与例子
    一些经验记录,主要是C# ToString()和 DateTime 之类的
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1863893.html
Copyright © 2020-2023  润新知