I have a sortable DatagridView with the last last row containing the sum of some columns. I want this summary row to always be the last row (bottom) of the datagridView.
At the moment, when I sort the datagridView column, the resulting row is sorted, I don't want this. I want the last row (summary row) of the DatagridView not to sort.
Is there any way to do this?
I found a solution:
I overloaded the sortcompare method as follows:
private void grid_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
try
{
if (e.RowIndex1 == this.dataGridView1.Rows.Count -1)
e.Handled = true;
if (e.RowIndex2 == this.dataGridView1.Rows.Count - 1)
e.Handled = true;
return;
}
catch (Exception ex)
{
ex.ToString();
}
}
source
share