2
I have a class Produtos
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 class Categoria
is as follows:
public class Categoria
{
public int cod { get; set; }
public string nome { get; set; }
}
When I wish to list the products in one DataGridView
, I want the lines of Produtos
have in the spine Categoria
with the property nome
of the class instance Categoria
which is within the Produto
.
But it is appearing like this at the time of listing the products in Datagridview:
Property of the "Category" column in the properties of DataGridView
:
How Product instances are being created in the SELECT I do in the database :
Produto prod = new Produto();
prod....(outros campos)
prod.categoria = CategoriaDAO.getCategoria(leitorSQL.GetInt32("codCategoria"));
This getCategory() method returns an instance of the Category class according to a product category code.
Some questions:
1 - There is the possibility to do this?
2 - It is a good practice of programming to put that (in this example) objects of type Produto
have an attribute of type Categoria
? Or would it be better to create two variables? One for the category code and the other for the name of Categoria
.
an option is you set the column as
DataGridViewComboBoxColumn
, and bind by category code, you can keep the appearance of a Textbox in the column options– Rovann Linhalis