数据绑定在列表与LT; T>到datagridview的 [英] Bind Data in List<T> to DatagridView
本文介绍了数据绑定在列表与LT; T>到datagridview的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将数据绑定到在C#中的datagridview。我怎么能表中的数据绑定到一个GridView请。
I am trying to bind data to a datagridview in C#. How can I bind table data to a gridview please.
下面是用我的代码。
获取所有数据
public IEnumerable<MailingList> getAllAddress()
{
return Entities.MailingLists.AsEnumerable();
}
数据源
Datasource
dgvAddresses.DataSource = new AddressAccess().getAllAddress();
由于某些原因没有出现。我怎样才能将数据绑定,请
For some reason nothing appears. How can I bind the data please.
推荐答案
您可以使用绑定源做到这一点:
You can do it using a Binding source:
var source = new BindingSource();
source.DataSource = new AddressAccess().getAllAddress().ToList();
dgvAddresses.AutoGenerateColumns=true;
dgvAddresses.DataSource = source;
这篇关于数据绑定在列表与LT; T>到datagridview的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文