zoukankan
html css js c++ java
DataGridView绑定List时无法进行添加删除操作的解决方法
将List<T>转换为BindingList<T>,然后设置DataGridView的DataSource为BindingList<T>!!
代码:
DataGridView.DataSource
=
new
BindingList
<
T
>
(List
<
T
>
);
将绑定BindingList<T>的DataSource转化为List<T>,同理
代码:
List
<
T
>
modelList
=
new
List
<
T
>
((BindingList
<
T
>
)
this
.DataGridView.DataSource);
说明:BindingList<T>和List<T>都有个构造函数,参数是
IEnumerable<T>,既然他们俩个都是继承
IEnumerable
,当然能相互转换。
下面是这个构造函数的执行过程:
public
List(IEnumerable
<
T
>
collection)
{
if
(collection
==
null
)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}
ICollection
<
T
>
is2
=
collection
as
ICollection
<
T
>
;
if
(is2
!=
null
)
{
int
count
=
is2.Count;
this
._items
=
new
T[count];
is2.CopyTo(
this
._items,
0
);
this
._size
=
count;
}
else
{
this
._size
=
0
;
this
._items
=
new
T[
4
];
using
(IEnumerator
<
T
>
enumerator
=
collection.GetEnumerator())
{
while
(enumerator.MoveNext())
{
this
.Add(enumerator.Current);
}
}
}
}
查看全文
相关阅读:
HDU 5119 Happy Matt Friends(DP || 高斯消元)
URAL 1698. Square Country 5(记忆化搜索)
POJ 2546 Circular Area(两个圆相交的面积)
URAL 1430. Crime and Punishment(数论)
HDU 1111 Secret Code (DFS)
HDU 1104 Remainder (BFS求最小步数 打印路径)
URAL 1091. Tmutarakan Exams(容斥原理)
PDO连接mysql8.0报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误
swoole简易实时聊天
centos安装netcat
原文地址:https://www.cnblogs.com/yoshirogu/p/1564846.html
最新文章
跟着刚哥学Redis
zookeeper的安装与配置(单机和集群)
Linux常用命令
Linux常用命令-jdk和Tomcat
Tomcat--各个目录详解(二)
Tomcat--安装与部署(一)
跟着刚哥学习Spring框架--事务配置(七)
windows下安装和配置mongoDB
题目一:给出一个n,代表有从1到n的数字[1,2,3,··· n],问可以构成多少种二叉搜索树?
梯度下降法和牛顿法的总结与比较
热门文章
正则化项L1和L2的区别
常见的损失函数
如何解决样本不均衡问题
局部加权回归
Linux 下spark安装
Win 10 +python3.5 之sklearn 的安装
pip 安装
Python用MySQLdb, pymssql 模块通过sshtunnel连接远程数据库
MySQL 删除重复数据
随笔……
Copyright © 2011-2022 走看看