0
My Datagridview receives product data from a database. They are: description, unit price and quantity. I programmatically added a subtotal column and added the * quantity unit price calculation. As I add items to the datagrid, a function does this calculation and adds the value to the correct line. The problem occurs when I add items whose names start with the same letter; Datagrid groups these products and messes up the order of subtotals.
My code:
foreach (int i in numerolinha) //adiciona valores no subtotal do datagrid
{
dgvpProd.Rows[i].Cells["Subtotal"].Value = qtxpreco[i];
}
foreach (DataGridViewColumn column in dgvpProd.Columns)//Bloqueia as colunas do Datagrid
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
The second foreach was a solution attempt blocking the ordering of columns by the user, but did not solve the alphabetic order problem. Some help?
Update: I found that the ordering is not alphabetical, but in the order in which the items were registered in the BD. Items that have smaller id’s are inserted at the top of Datagridview and vice versa. Still no solution.
How is the structure of
query
who populate thedatagridview
?– gato
What is the field that is the ordering criterion?
– gato
I didn’t understand very well the question of structure but if it is the sequence in which the data is saved, it would be this: id, description, unit price, total and subtotal; where id is hidden and subtotal is an additional column that is not in the BD. In the second question: the desired criterion is the insertion order, but it seems that it is ordering by items of the same name.
– Vanderlei
Dener, your question gave me a clue: I think it’s being ordered by ID since this field is hidden. I will try to create a restriction to not allow 2 products with the same ID, because it is illogical two identical items since I can assign quantity.
– Vanderlei
Are you populating datagridview for a query? If you show me how your query is, and show the routine that populates the whole datagridview, with the fields:
descricao
,preco unitario
,quantidade
,subtotal
.– gato
You can have two identical items, however they can differ in some aspect, but I don’t know if it’s a requirement of your system.
– gato
itemTableAdapter.Insert(id_orcam, id_produto, quantidade, preco_item);
itemTableAdapter.Fill(vorc2DataSet.Item);
dgvpProd.DataSource = produtoTableAdapter.GetDataByIDOrc(id_orcam); //Este é um resumo da rotina
– Vanderlei
This last snippet updates the Datagrid with the following query: SELECT MAX(id) AS Expr1 FROM Budget that is already stored in the datasource.
– Vanderlei