C# 中 datagridview 绑定BindingList类型和更新
C# 中的datagridview是一个非常有用且强大的控件,可以用来绑定数据库、绑定LIST类型的变量等等。
这里我们说一说绑定List类型并实时更新datagridview的情况。实时更新,指的是在我操作BindingList时(删除/Add)等操作的时候,datagridview也会发生相应变化。
想要达到此种目的,需要达成以下几个条件:
1.datagridview的datasource被指定为BindingList类型
2.在datagridview的编辑列中,将列里面的dataproperty指定为BindingList下的某一个属性
3.这个属性(成员变量)还必须是通过get/set这种方式来获取的,不能是直接得到的public类型的变量。
代码示例:
声明bindinglist:
BindingList<aHost> IpList = new BindingList<aHost>();
ahost类:
class aHost
{
string _Ip = "";
string _isAlive = "No";
public string sPorts; public string Ip
{
get {return _Ip;}
set { _Ip = value; }
} public string isAlive
{
get { return _isAlive; }
set { _isAlive = value; }
}
}
建立绑定关系:
public Form1()
{
InitializeComponent();
IpList.Add(new Model.aHost("192.168.1.1","Nope"));
dgHostList.AutoGenerateColumns = false;
dgHostList.DataSource = IpList;
}
设置datapropertyname就不演示了,很简单。
效果:
C# 中 datagridview 绑定BindingList类型和更新的更多相关文章
- C# 中DataGridView 绑定List<T>做数据源的操作问题
若想将 List<T>作为DataGridView的数据源,然后后续还想继续操作的话,需要将List<T>赋值给BindingList对象, 然后直接将BindingList赋 ...
- DataGridView绑定BindingList<T>带数据排序的类
本文章转载:http://yuyingying1986.blog.hexun.com/30905610_d.html DataGridView绑定List<T>类时候,不会自动的进行排序. ...
- c# winform 中DataGridView绑定List<T> 不能显示数据
遇到问题 DataGridView绑定List后,List更新后再次绑定不显示数据 datagridview 绑定数据源的时候 用List是不能显示修改内容的..要用binginglist<T& ...
- C# Winform中DataGridView绑定后DataGridViewCheckBoxColumn无法显示的问题
在控件DataGridView绑定数据源后,发现DataGridViewCheckBoxColumn不能显示当前的check值.经过一番努力,现将完整代码奉献出来,仅供参考. 错误代码: /*禁止自动 ...
- DataGridView 绑定List<>数据的更新
使用BindingSource做为中间数据源,使用 bindingSource1.DataSource = productOrderList;dataGridView1.DataSource = bi ...
- winfrom中DataGridView绑定数据控件中DataGridViewCheckBoxColumn怎么选中
; i < this.dataGridView1.Rows.Count; i++) { this.dataGridView1.Rows[i].Cells["CheckBoxCulums ...
- C# DataGridView绑定数据源的几种常见方式
开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnect ...
- 基于.net的分布式系统限流组件 C# DataGridView绑定List对象时,利用BindingList来实现增删查改 .net中ThreadPool与Task的认识总结 C# 排序技术研究与对比 基于.net的通用内存缓存模型组件 Scala学习笔记:重要语法特性
基于.net的分布式系统限流组件 在互联网应用中,流量洪峰是常有的事情.在应对流量洪峰时,通用的处理模式一般有排队.限流,这样可以非常直接有效的保护系统,防止系统被打爆.另外,通过限流技术手段,可 ...
- C#中数据源绑定DataSource以及相关控件(DataGridView)的使用总结
我们在编程过程中,会涉及到表格数据的显示,存储等,就可能涉及到DataGridView,DataSource, DataTable等概念. 下面我就我自己模糊的一些知识点串讲以下: 1)首先我要讲的是 ...
随机推荐
- cdoj 1143 传输数据 最大流
传输数据 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1143 Descri ...
- Android-----使用Button特效 selector+shape
当然除了使用drawable这样的图片外今天谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape.gradient.stroke.corners等. 我们就以 ...
- [Angular 2] Controlling Rx Subscriptions with Async Pipe and BehaviorSubjects
Each time you use the Async Pipe, you create a new subscription to the stream in the template. This ...
- [Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive
You can easily show the user which route they are on using Angular 2’s routerLinkActive. Whenever a ...
- Flex-Security权限控制框架
转自:http://code.google.com/p/flex-security/ flex UI组件权限控制框架 一.快速开始 1) 下载并添加flex_security.swf在你的flex l ...
- VC编译连接选项详解(转)
大家可能一直在用VC开发软件,但是对于这个编译器却未必很了解.原因是多方面的.大多数情况下,我们只停留在“使用”它,而不会想去“了解”它.因为它只是一个工具,我们宁可把更多的精力放在C++语言和软件设 ...
- matplotlib作图中文显示问题
def set_ch(): from pylab import mpl mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体 mpl.rcPa ...
- DbHelperSQL 判断数据库表结构公用方法
#region 公用方法 /// <summary> /// 判断是否存在某表的某个字段 /// </summary> ...
- 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
Drainage Ditches 题目抽象:给你m条边u,v,c. n个定点,源点1,汇点n.求最大流. 最好的入门题,各种算法都可以拿来练习 (1): 一般增广路算法 ford() #in ...
- iOS 如何判断当前网络连接状态 网络是否正常 网络是否可用
网络资源:出处http://blog.csdn.net/mad1989/article/details/8987368 众所周知,我们在开发APP时,涉及网络连接的时候,都会想着提前判断一下当前的 ...