1.DataGridView数据绑定

  1. namespace WindowsFormsApplication1
  2. {
  3. public partial class Form1 : Form
  4. {
  5. private List<Student> _students = new List<Student>();
  6.  
  7. public Form1()
  8. {
  9. InitializeComponent();
  10.  
  11. _students.Add(new Student() { Name = "黄勇", Age = , School = "哈尔滨商业大学" });
  12.  
  13. _students.Add(new Student() { Name = "何明", Age = , School = "湖南理工大学" });
  14.  
  15. _students.Add(new Student() { Name = "Tommy", Age = , School = "香港大学" });
  16.  
  17. var bindingList = new BindingList<Student>(_students);
  18.  
  19. dataGridView1.DataSource = bindingList;
  20.  
  21. }
  22.  
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. var student = _students.FirstOrDefault(item => item.Name.Equals("何明"));
  26.  
  27. if (student != null)
  28. {
  29. //可动态刷新UI
  30. student.Name = "";
  31. }
  32. }
  33. }
  34.  
  35. public class Student : INotifyPropertyChanged
  36. {
  37. public event PropertyChangedEventHandler PropertyChanged;
  38.  
  39. private String _name;
  40. private Int32 _age;
  41. private String _school;
  42.  
  43. public String Name
  44. {
  45. get
  46. {
  47. return _name;
  48. }
  49. set
  50. {
  51. if (value != _name)
  52. {
  53. _name = value;
  54. this.NotifyPropertyChanged("Name");
  55. }
  56. }
  57. }
  58.  
  59. public Int32 Age
  60. {
  61. get
  62. {
  63. return _age;
  64. }
  65. set
  66. {
  67. if (value != _age)
  68. {
  69. _age = value;
  70. this.NotifyPropertyChanged("Age");
  71. }
  72. }
  73. }
  74.  
  75. public String School
  76. {
  77. get
  78. {
  79. return _school;
  80. }
  81. set
  82. {
  83. if (value != _school)
  84. {
  85. _school = value;
  86. this.NotifyPropertyChanged("School");
  87. }
  88. }
  89. }
  90.  
  91. private void NotifyPropertyChanged(string name)
  92. {
  93. if (PropertyChanged != null)
  94. {
  95. PropertyChanged(this, new PropertyChangedEventArgs(name));
  96. }
  97. }
  98. }
  99. }

Winform 数据绑定的更多相关文章

  1. 【转】详解Data Binding 通过几个简单示例深入了解WinForm数据绑定特性

    原文地址:http://www.cnblogs.com/lichence/archive/2012/02/17/2356001.html

  2. DataGridView控件

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  3. DataGridView控件-[引用]

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  4. c#dataGridView 知识

    一.单元格内容的操作 // 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Conso ...

  5. DataGridView控件使用大全说明-各种常用操作与高级操作

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  6. DataGridView控件使用大全

    转自:http://www.cnblogs.com/xiaofengfeng/archive/2011/04/16/2018504.html DataGridView控件 DataGridView是用 ...

  7. C#实现WinForm DataGridView控件支持叠加数据绑定

    我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...

  8. C# WinForm 中ComboBox数据绑定的问题 (转)

    来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...

  9. WinForm控件复杂数据绑定常用数据源(对Combobox,DataGridView等控件DataSource赋值的多种方法)

    开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1) 简单数据绑定 简单的数据绑定是将用户控件的某一个属性绑定至某一个类型实例上的某一属性.采用如下形式进行绑定 ...

随机推荐

  1. mac安装ruby-oci8

    1.安装xcode 2.从oracle官网下载以下安装包 instantclient-basic-macos.x64-12.1.0.2.0.zip instantclient-sdk-macos.x6 ...

  2. 闰年相关的问题v3.0——计算有多少闰年

    # include<stdio.h>int main(){ int a,b,i; int sum = 0; printf("Input your birth year:" ...

  3. STM32 USB设备描述符、配置描述符、端点描述符含义

    查了一整天的资料,自己把不懂的全部试了一遍 一下是程序以及注释 /* USB设备描述符*/ const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ ...

  4. Divisibility题解

    From lyh 学长 2018.5.3 信(liang)心(liang)杯T3 一道略弱的数论题. 题目描述 给定 n个数,问是否能从中选出恰好 k个数,使得这些数两两之差可以被 m 整除. 输入输 ...

  5. kafka配置参数详解

    Broker  Configs Property Default Description broker.id   每个broker都可以用一个唯一的非负整数id进行标识:这个id可以作为broker的 ...

  6. Android 9 适配怎么做? “QQ音乐”优化实录

    WeTest 导读 2018年8月7日,Google对外发布最新 Android 9.0 正式版系统,并宣布系统版本Android P 被正式命名为代号“Pie”,最新系统已经正式推送包括谷歌Pixe ...

  7. hdu1175连连看(dfs+细节)

    连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. git push origin master 错误解决办法

    一.错误代码如下: error: failed to push some refs to 'https://github.com/wbingithub/drag.git' 二.在网上搜了一下,如下写就 ...

  9. python中的迭代器与生成器

    迭代器 迭代器的引入 假如我现在有一个列表l=['a','b','c','d','e'],我想取列表中的内容,那么有几种方式? 1.通过索引取值 ,如了l[0],l[1] 2.通过for循环取值 fo ...

  10. 洪水!(Flooded! ACM/ICPC World Final 1999,UVa815)

    题目描述:竞赛入门经典的习题4-10 解题思路:1.把各个网格想象成一个数组 2.排序 3.雨水总体积去铺满 //太懒了只写了求海拔 #include <stdio.h> #define ...