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) 简单数据绑定 简单的数据绑定是将用户控件的某一个属性绑定至某一个类型实例上的某一属性.采用如下形式进行绑定 ...
随机推荐
- UDP server Code
Code Example: The following programs demonstrate the use of getaddrinfo(), gai_strerror(), freeaddri ...
- categorical[np.arange(n), y] = 1 IndexError: index 2 is out of bounds for axis 1 with size 2
我的错误的代码是:train_labels = np_utils.to_categorical(train_labels,num_classes = 3) 错误的原因: IndexError: ind ...
- 利用.NET Code Contracts实现运行时验证
.NET的Contract类库是Declarative Programming实践的一部分,可以对日常编程带来很多好处: 提高代码可读性,使用者一看Require, Ensure就知道这方法接受什么输 ...
- Java:List判空的条件:List=null 和 List.size = 0
当需要对一个LIst进行判空操作时我们可使用如下两个语句: if (list == null || list.size() == 0) {} if (list != null && l ...
- kaggle入门--泰坦尼克号之灾(手把手教你)
作者:炼己者 具体操作请看这里-- https://www.jianshu.com/p/e79a8c41cb1a 大家也可以看PDF版,用jupyter notebook写的,视觉效果上感觉会更棒 链 ...
- Linux命令应用大词典-第34章 打印与传真
34.1 lpr:打印文件 34.2 lpq:显示打印队列状态 34.3 lprm:取消打印作业 34.4 lpstat:显示cups状态信息 34.5 cupsaccept:接受作业发送到目的地 3 ...
- Response对象及常用方法
void addCookie(Cookie cookie)给客户端添加一个Cookie对象,以保存客户端的信息 void addDateHeader(String name,long value) 添 ...
- Spring Boot下的lombok安装 (日志) 不能识别log变量问题
参考地址:http://blog.csdn.net/blueheart20/article/details/52909775 ps:除了要加载依赖之外 还要安装lombok插件
- Visual Studio Code——PHP Debug扩展
最近在使用PHP开发,使用了很多IDE,发现都不是很顺手,之前一直都在使用Sublime Text,但是作为一个爱折腾的人,当我发现VS Code以后觉得很是很适合自己的编程需要的.配置过程中遇到了一 ...
- django 增删改查操作 数据库Mysql
下面介绍一下django增删改查操作: 1.view.py # -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom dja ...