2014-10-29 34 views
1

我需要在表中顯示子實體。winform datagridviewtextboxcolumn datapropertyname child

// 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" 
} 

該應用程序是顯示一個空單元格

+3

的可能的複製[DataGridViewColumn.DataPropertyName性](https://stackoverflow.com/questions/2221207/datagridviewcolumn-datapropertyname-property) – 2017-08-23 06:05:42

回答

-1

已經這樣做了。工作

// 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" 
} 
相關問題