让像我有以下类的DataGridView - 使用DataPropertyName显示子元素属性
public class Master
{
public string MasterName = "Something";
public List<Detail> details = new List<Detail>();
}
public class Detail
{
public string Foo = "Test";
}
然后我要显示详细信息对象的集合中的一个DataGridView,使用下面
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "Details.Foo";
column.HeaderText = "Foo header";
dgv.Columns.Add(column);
代码
该列显示在网格中,但没有值
你确定DataPropertyName是你想要什么?看起来你正在寻找更多的价值。我怀疑你不与ASP.Net,这是我最熟悉的工作,但我会检查DataGridViewTextBoxColumn的其他属性,看看是否有别的东西出现,这将使你所需要的。 – Melanie
@Melanie我正在使用Windows窗体。我会看看其他属性 – Andrey
另外,当我使用另一个对象的属性它的罚款,如:DataPropertyName =“MasterName” – Andrey