【问题标题】:DataGridView binding from list problem列表问题中的 DataGridView 绑定
【发布时间】:2009-05-14 05:53:02
【问题描述】:

我有一个我试图绑定到 DataGridView 的客户列表。我有两个看起来像这样的数据类:

public class Customer
{
     public string Name { get; set; }
     public AddressDetail Address { get; set; }
}

public class AddressDetail
{
     public string StreetAddress { get; set; }
     public string City { get; set; }
}

然后当我尝试填充 DataGridView 时,我使用:

CustomerInfo custInfo = new CustomerInfo();
CustomerGrid.DataSource = custInfo.GetCustomers();

GetCustomers 将返回一个客户列表。我的问题是地址列只有一列,并在列中显示“地址”。在 DataGridView 中为 Address 类的所有成员显示列的最佳方式是什么。

【问题讨论】:

    标签: c# .net datagridview


    【解决方案1】:

    我的问题是地址栏是 只有一列并在 列。

    我想你想说“在标题栏中”。

    您可以组装一个包含 StreetAddress 和 City 的句子,并在网格中 Address 列的每个字段中显示。

    【讨论】:

    • 呜呼!谢谢!我刚刚在 AddressDetail 中对 ToString 进行了覆盖以连接地址,并且效果很好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多