c# - 将 List<T> 中的数据绑定(bind)到 DatagridView

标签 c# data-binding datagridview ienumerable

我正在尝试将数据绑定(bind)到 C# 中的数据 GridView 。请问如何将表格数据绑定(bind)到 gridview。

下面是我使用的代码。

获取所有数据。

public IEnumerable<MailingList> getAllAddress()
    {
        return Entities.MailingLists.AsEnumerable();
    }

数据源

dgvAddresses.DataSource = new AddressAccess().getAllAddress();

由于某种原因什么都没有出现。请问如何绑定(bind)数据。

最佳答案

您可以使用绑定(bind)源来做到这一点:

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

关于c# - 将 List<T> 中的数据绑定(bind)到 DatagridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19404222/

相关文章:

c# - 使用 Jint/Trap console.log 调用从 C# 运行 javascript

c# - 我自己的异常处理程序仍然抛出异常并使应用程序崩溃

c# - 在哪里可以找到 System.Runtime.Caching 以在 Windows 窗体应用程序中引用

c# - 如何防止绑定(bind)触发 TextChanged 事件?

c# - 组合框数据绑定(bind)

c# - 如何在 datagridview 单元格中选择一行?

c# - 定时器精度和分辨率是什么意思?

c# - DataGrid 的数据绑定(bind)不起作用?

c# - 并发冲突 : the UpdateCommand affected 0 of the expected 1 records

c# - 单击下一步转到第一个选项卡时,ASP.NET C# datagridview 在第二个选项卡内分页