设为首页 加入收藏

TOP

WinForm DataGridView双向数据绑定(二)
2019-08-30 00:47:10 】 浏览:90
Tags:WinForm DataGridView 双向 数据 绑定
ple("新人", "湖南", 30)); 89 } 90 91 private void mDeleteItemBtn_Click(object sender, EventArgs e) 92 { 93 if (this.Peoples.Count > 0) 94 { 95 this.Peoples.RemoveAt(0); 96 } 97 } 98 99 private void mChangeItemValueBtn_Click(object sender, EventArgs e) 100 { 101 if (Peoples.Count > 0) 102 { 103 this.Peoples[0].Address = "浙江"; 104 //如果People没有继承INotifyPropertyChanged接口,则需要下面注释的代码,来引发改变通知事件。 105 //this.Peoples.ResetItem(0);//引发改变通知 106 } 107 108 if (Peoples.Count > 1) 109 { 110 this.Peoples[1].Age = Peoples[1].Age + 1; 111 //this.Peoples.ResetItem(1);//引发改变通知 112 } 113 } 114 } 115 } Form1.cs
 1 ///****************************************************************************
 2 /// CLR版本     :4.0.30319.42000
 3 /// 邮    箱    :282780854@qq.com
 4 /// 博    客    :https://www.cnblogs.com/it89/
 5 /// 创 建 者    :龙腾虎跃
 6 /// 创建日期    :2019/1/15 21:03:04 
 7 /// 功能描述    :
 8 /// 使用说明    :
 9 ///****************************************************************************
10 using System;
11 using System.ComponentModel;
12 using System.Runtime.CompilerServices;
13 
14 namespace TestDataGridViewBind
15 {
16     /// <summary>
17     /// 
18     /// </summary>
19     public class People : INotifyPropertyChanged
20     {
21         #region "Public Section"
22         public string Name
23         {
24             get => mName;
25             set { mName = value; NotifyPropertyChanged("Name"); }
26         }
27 
28         public string Address
29         {
30             get => mAddresss;
31             set { mAddresss = value; NotifyPropertyChanged("Address"); }
32         }
33 
34         public int Age
35         {
36             get => mAge;
37             set { mAge = value; NotifyPropertyChanged("Age"); }
38         }
39 
40         public People(string name, string address, int age)
41         {
42             mName = name;
43             mAddresss = address;
44             mAge = age;
45         }
46 
47         public event PropertyChangedEventHandler PropertyChanged;
48 
49         #endregion
50 
51         #region "Private Section"
52         private string mName;
53         private string mAddresss;
54         private int mAge;
55 
56         /// <summary>
57         /// 该方法由每个属性Set访问器调用。
58         /// </summary>
59         /// <param name="propertyName"></param>
60         private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
61         {
62             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
63         }
64 
65         #endregion
66     }
67 }
People.cs
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Win10系统修改主机名、用户名称和.. 下一篇Windows To Go入坑记录

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目