I have a DataGridView that should show data between related tables and I can not show the data correctly, it shows the name of the nameSpace followed by the name of the class. I saw some things and they showed an override, but I also read that it is not good practice and suggested that you do it through the cellFormating event.
What happens to me is this:
ThisclassisintheDTOnamespace
publicclassDespesa{publicintid_despesa{get;set;}publicCategoriacategoria{get;set;}publicstringdescricao{get;set;}publicdecimalvalor{get;set;}publicMesmes{get;set;}publicstringprevisao{get;set;}publicForma_Pagamentoforma_Pagamento{get;set;}publicPeriodoperiodo{get;set;}}
Thenmyexpensecollectionwillinheritanexpenselist
publicclassDespesaCollection:List<Despesa>{}
InthebusinesslayerIputalltheexpenseswithinthecollection
foreach(DataRowlinhainDataTableDespesas.Rows){Despesadespesa=newDespesa();despesa.id_despesa=Convert.ToInt32(linha["id_despesa"]);
despesa.categoria = new Categoria();
despesa.categoria.id_categoria = Convert.ToInt32(linha["id_categoria"]);
despesa.descricao = linha["descricao"].ToString();
despesa.valor = Convert.ToDecimal(linha["valor"]);
despesa.mes = new Mes();
despesa.mes.id_mes = Convert.ToInt32(linha["id_mes"]);
despesa.previsao = linha["previsao"].ToString();
despesa.forma_Pagamento = new Forma_Pagamento();
despesa.forma_Pagamento.id_forma_pagamento = Convert.ToInt32(linha["id_formaPagamento"]);
despesa.periodo = new Periodo();
despesa.periodo.id_periodo = Convert.ToInt32(linha["id_periodo"]);
despesaCollection.Add(despesa);
}
And here's how I load the collection to display in the dataGridView.
private void carregarDataGridView()
{
DespesaCollection despesaCollection = new DespesaCollection();
DespesaNegocio despesaNegocio = new DespesaNegocio();
despesaCollection = despesaNegocio.ConsultarTudo();
dataGridView1.DataSource = null;
dataGridView1.DataSource = despesaCollection;
dataGridView1.Refresh();
}