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);
}
}
}
}
查看全文
相关阅读:
strace命令跟踪ping调用函数整理
小知识记录:第XII篇
学习笔记:《Kali Linux 2 网络渗透测试 实践指南 第2版》之主动扫描(Nmap)
学习笔记:《Kali Linux 2 网络渗透测试 实践指南 第2版》之被动扫描(Maltego)
学习笔记:《Kali Linux 2 网络渗透测试 实践指南 第2版》之kali Linux使用基础
《柯尔特思维教程》-第3章(交互)- 前言
《柯尔特思维教程》-第2章(组织)- 前言
《柯尔特思维教程》-第1章(广度)- 前言
《柯尔特思维教程》-第3章(交互)- 第10节:结果
《柯尔特思维教程》-第3章(交互)- 第9节:失误-2:错误和偏见
原文地址:https://www.cnblogs.com/yoshirogu/p/1564846.html
最新文章
react + ant-design 仿知乎&V2EX风格社区
13-System类和Math类
12-Java比较器
11--StringBuffer、StringBuilder
10-java.lang.String类的使用
09-JDK5.0线程创建的方式
Windows下的 mysql备份脚本文件
oracle日期格式转换 to_date(),to_char()
Idea清理缓存
06_触发器
热门文章
05-存储函数与存储过程
vCenter挂载群晖NFS共享存储
工程代码维护的思考:完美的工程代码存在么?
CSS中的position属性
XStream组件预警以及修复指引
lrzsz(一款好用的linux本地与远程数据传输工具)
jenkins pipeline docker 发布项目
Sonar Qube 持续集成实践
Java环境搭建以及开发工具安装
KeepassXC使用教程
Copyright © 2011-2022 走看看