winform datagridviewtextboxcolumn datapropertyname child

时间:2014-10-29 11:36:34

标签: c# winforms datagridview

我需要在表格中显示子实体。

// Entitys
public class Sp
{
   public int Id { get; set; }
   public int IdDict { get; set; }
   public Dict Dict { get; set; }
}

public class Dict
{
   public int Id { get; set; }
   public string Caption { get; set; }
}

如何绑定?

var c = new DataGridViewTextBoxColumn
{
    // How can I do?
    DataPropertyName = "Dict.Caption"  
}

应用程序显示空单元格

1 个答案:

答案 0 :(得分:0)

已经这样做了。作品

// Entitys
public class Sp  
{
    public int Id { get; set; }
    public int IdDict { get; set; }
    public Dict Dicts { get; set; }
    public DictCaption { get { return Dicts.Caption; } }
} 
public class Dict
{
    public int Id { get; set; }
    public string Caption { get; set; }
}
.... 
dataGridView.DataSource = dbContext.Set<Sp>().ToList;
var c = new DataGridViewTextBoxColumn
{
    DataPropertyName = "DictCaption"  
}