Winform 数据绑定
1.DataGridView数据绑定
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private List<Student> _students = new List<Student>();
- public Form1()
- {
- InitializeComponent();
- _students.Add(new Student() { Name = "黄勇", Age = , School = "哈尔滨商业大学" });
- _students.Add(new Student() { Name = "何明", Age = , School = "湖南理工大学" });
- _students.Add(new Student() { Name = "Tommy", Age = , School = "香港大学" });
- var bindingList = new BindingList<Student>(_students);
- dataGridView1.DataSource = bindingList;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- var student = _students.FirstOrDefault(item => item.Name.Equals("何明"));
- if (student != null)
- {
- //可动态刷新UI
- student.Name = "";
- }
- }
- }
- public class Student : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private String _name;
- private Int32 _age;
- private String _school;
- public String Name
- {
- get
- {
- return _name;
- }
- set
- {
- if (value != _name)
- {
- _name = value;
- this.NotifyPropertyChanged("Name");
- }
- }
- }
- public Int32 Age
- {
- get
- {
- return _age;
- }
- set
- {
- if (value != _age)
- {
- _age = value;
- this.NotifyPropertyChanged("Age");
- }
- }
- }
- public String School
- {
- get
- {
- return _school;
- }
- set
- {
- if (value != _school)
- {
- _school = value;
- this.NotifyPropertyChanged("School");
- }
- }
- }
- private void NotifyPropertyChanged(string name)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(name));
- }
- }
- }
- }
Winform 数据绑定的更多相关文章
- 【转】详解Data Binding 通过几个简单示例深入了解WinForm数据绑定特性
原文地址:http://www.cnblogs.com/lichence/archive/2012/02/17/2356001.html
- DataGridView控件
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- DataGridView控件-[引用]
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- c#dataGridView 知识
一.单元格内容的操作 // 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Conso ...
- DataGridView控件使用大全说明-各种常用操作与高级操作
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- DataGridView控件使用大全
转自:http://www.cnblogs.com/xiaofengfeng/archive/2011/04/16/2018504.html DataGridView控件 DataGridView是用 ...
- C#实现WinForm DataGridView控件支持叠加数据绑定
我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...
- C# WinForm 中ComboBox数据绑定的问题 (转)
来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...
- WinForm控件复杂数据绑定常用数据源(对Combobox,DataGridView等控件DataSource赋值的多种方法)
开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1) 简单数据绑定 简单的数据绑定是将用户控件的某一个属性绑定至某一个类型实例上的某一属性.采用如下形式进行绑定 ...
随机推荐
- mac安装ruby-oci8
1.安装xcode 2.从oracle官网下载以下安装包 instantclient-basic-macos.x64-12.1.0.2.0.zip instantclient-sdk-macos.x6 ...
- 闰年相关的问题v3.0——计算有多少闰年
# include<stdio.h>int main(){ int a,b,i; int sum = 0; printf("Input your birth year:" ...
- STM32 USB设备描述符、配置描述符、端点描述符含义
查了一整天的资料,自己把不懂的全部试了一遍 一下是程序以及注释 /* USB设备描述符*/ const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ ...
- Divisibility题解
From lyh 学长 2018.5.3 信(liang)心(liang)杯T3 一道略弱的数论题. 题目描述 给定 n个数,问是否能从中选出恰好 k个数,使得这些数两两之差可以被 m 整除. 输入输 ...
- kafka配置参数详解
Broker Configs Property Default Description broker.id 每个broker都可以用一个唯一的非负整数id进行标识:这个id可以作为broker的 ...
- Android 9 适配怎么做? “QQ音乐”优化实录
WeTest 导读 2018年8月7日,Google对外发布最新 Android 9.0 正式版系统,并宣布系统版本Android P 被正式命名为代号“Pie”,最新系统已经正式推送包括谷歌Pixe ...
- hdu1175连连看(dfs+细节)
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- git push origin master 错误解决办法
一.错误代码如下: error: failed to push some refs to 'https://github.com/wbingithub/drag.git' 二.在网上搜了一下,如下写就 ...
- python中的迭代器与生成器
迭代器 迭代器的引入 假如我现在有一个列表l=['a','b','c','d','e'],我想取列表中的内容,那么有几种方式? 1.通过索引取值 ,如了l[0],l[1] 2.通过for循环取值 fo ...
- 洪水!(Flooded! ACM/ICPC World Final 1999,UVa815)
题目描述:竞赛入门经典的习题4-10 解题思路:1.把各个网格想象成一个数组 2.排序 3.雨水总体积去铺满 //太懒了只写了求海拔 #include <stdio.h> #define ...