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 ...
- ACM1003:Max Sum
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...
- mac下使用git的冲突的解决方案
博主之前一直是在windows系统下进行软件代码的开发,window下有很多git的使用工具,如tortoisegit等是个很好的git项目管理工具.而再mac版下的git项目代码管理工具,本人找了好 ...
- axios请求封装和异常统一处理
前端网络请求封装前端采用了axios来处理网络请求,为了避免在每次请求时都去判断各种各样的网络情况,比如连接超时.服务器内部错误.权限不足等等不一而足,我对axios进行了简单的封装,这里主要使用了a ...
- git忽略项gitegnore配置
在git中如果想忽略掉某个文件, 不让这个文件提交到版本库中,可以使用修改 .gitignore 文件的方法.这个文件每一行保存了一个匹配的规则 例如 # 此为注释 – 将被 Git 忽略 *.a # ...
- Linux下安装Nginx并实现socket代理
nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息. 正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好. ububtu平台编译环 ...
- Docker - 常用命令集
启动容器 docker run -d -p 58080:8080 -p 58000:8000 --name mytomcat1.0 -v /root/webapps/:/opt/apache-tomc ...
- Mac brew安装redis
1.安装redis $ brew install redis Error:Failed to download resource "reds" // 下载reds失败 不过不需要 ...
- 2019年猪年海报PSD模板-第六部分
14套精美猪年海报,免费猪年海报,下载地址:百度网盘,https://pan.baidu.com/s/1WdlIiIdj1VVWxI4je0ebKw
- 「Python」matplotlib备忘录
总结了一下网上现有的资源,得到了一些东西.随手做个备忘. 更多设置见:https://matplotlib.org/users/customizing.html. 导入 import matplotl ...