WPF Datagrid (Prevent DataGrid Last Row From Being Sorted On Column Header Clicked)
Here's the WPF version of prevent total rows from being sorted. Images: 1. Form Load, no column header is clicked (unsorted records) 2. Name header is clicked (sorting by column). The names are sorted alphabetically. Below are the methods used: /// <summary> /// column header clicked(sorting) /// </summary> private void dgProducts_Sorting( object sender, DataGridSortingEventArgs e) { DataRowView rv = (DataRowView)dgProducts.Items[dgProducts.Items.Count - 1]; if (rv[0].ToString().Contains( "Total:" )) { dvCopy = dgProducts.Items.SourceCollection as DataView; rv.Delete(); } sorted_aborted = e.Handled; } /// <summary> /// layout is updated /// </summary> private void dgProducts_LayoutUpdated( object sender, EventArgs e) { if (!sorted_aborted) { ...