My DataGridView receives product data from a database. They are: description, unit price and quantity. I programmatically added a subtotal column and added the unit price calculation * quantity. As I add items to the datagrid, a function does this calculation and adds the value to the correct row. The problem happens when I add items whose names begin with the same letter; Datagrid groups these products and messes the order of the 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 column sorting by the user, but it does not solve the alphabetical order problem. Any help?
Update: I found that the ordering is not alphabetic, but in the order in which the items were registered in the DB. Items that have smaller id's are inserted at the top of the DatagridView and vice versa. Still no solution.