I'm trying display relationship of Classes in DataGridView but I can't do it. I have 3 classes, Produto
, Unidade
and ItemVenda
these classes contain relations between them and I can't display these relations in DataGridView. Using foreach
in the Console
displayed the relations fine.
How could I do it ?
Classes Relationship
public class Unidade{
public Integer id {set;get;}
public String descricao {set;get;};
public Unidade(){}
}
public class Produto{
public Long id {set;get;};
public String descricao {set;get;};
public Unidade unidade {set;get;}
public Produto(){}
}
public class ItemVenda{
public Long id {set;get;}
public Produto produto {set;get;}
public ItemVenda(){}
}
Trying display in DataGridView
private void defineGrid(){
gridItensVenda.AutoGenerateColumns = false;
IList<ItemVenda> lista = new ItemVendaDAO().findItensByVenda(venda);
gridItensVenda.DataSource = lista;
//Display Produto - works fine
DataGridViewColumn c1 = new DataGridViewTextBoxColumn();
c1.DataPropertyName = "produto";
c1.HeaderText = "Produto";
//Display Unidade of Produto doesn't work
DataGridViewColumn c2 = new DataGridViewTextBoxColumn();
c2.DataPropertyName = "produto.unidade";
c2.HeaderText = "Unidade";
//add columns to grid
gridItensVenda.Columns.Add(c1);
gridItensVenda.Columns.Add(c2);
}