I have a Products class with the following attributes:
public class Produto
{
public int cod { get; set; }
public string codBarras { get; set; }
public string nome { get; set; }
public Categoria categoria { get; set; }
public Decimal precoCompra { get; set; }
public Decimal precoVenda { get; set; }
public Decimal qtdEstoque { get; set; }
public string descricao { get; set; }
}
The Category class is as follows:
public class Categoria
{
public int cod { get; set; }
public string nome { get; set; }
}
When I want to list the products in a DataGridView, I want the Product lines to have in the "Category" column with the "name" property of the instance of the Category class that is within the Product instance.
But it is showing up at the time of listing the products in the DataGridView:
Propertyofthe"Category" column in DataGridView properties:
HowProductinstancesarebeingcreatedintheSELECTImakeinthedatabase:
Produtoprod=newProduto();prod....(outroscampos)prod.categoria=CategoriaDAO.getCategoria(leitorSQL.GetInt32("codCategoria"));
This getCategory () method returns an instance of the Category class according to the category code of a product.
Some questions:
1 - Is there a way to do this?
2 - Is it a good programming practice to put (in this example) the objects of type Product have an attribute of type Category? Or would it be better to create two variables? Being one for the category code and another for the Category name.