[英]Binding List<T> with datagridview in C#
I would like to know what is the difference between binding list directly to datagridview datasource and binding Bindingsource to datagridview. 我想知道绑定列表直接与datagridview数据源和绑定Bindingsource到datagridview有什么区别。 Here is example:
这是一个例子:
Ex1: EX1:
List<Employee> list = this.GetEmployees();
dgvEmployees.Datasource = list;
Ex2: EX2:
List<Employee> list = this.GetEmployees();
BindingSource soure = new BindingSource();
soure.Datasource = list;
dgvEmployees.Datasource = soure;
So, which one should be the good practice? 那么,哪一个应该是好的做法?
In general, using Datasource
directly is for simple cases and using a BindingSource
is for more complex cases. 通常,直接使用
Datasource
是为了简单的情况,使用BindingSource
是为了更复杂的情况。 When all you want to do is display data and don't really care about modifying it before it's displayed, feel free to use Datasource
当您想要做的只是显示数据并且在显示数据之前并不真正关心修改数据时,请随意使用
Datasource
BindingSource
on the other hand, allows you to (not an exhaustive list): 另一方面,
BindingSource
允许您(不是详尽的列表):
Format
method to transform the list data before the user sees it, and a Parse
method to transform the list data back after the user edits it Format
方法以在用户看到列表数据之前对其进行转换,并使用Parse
方法在用户编辑列表数据后将其转换回来
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.