简体   繁体   English

绑定列表中的数据<T>到数据网格视图

[英]Bind Data in List<T> to DatagridView

I am trying to bind data to a datagridview in C#.我正在尝试将数据绑定到 C# 中的 datagridview。 How can I bind table data to a gridview please.请问如何将表数据绑定到gridview。

Below is my code used.下面是我使用的代码。

Getting all data.获取所有数据。

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:您可以使用 Binding 源来做到这一点:

     var source = new BindingSource();
     source.DataSource = new AddressAccess().getAllAddress().ToList();
     dgvAddresses.AutoGenerateColumns=true;
     dgvAddresses.DataSource = source;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM