I am using a WPF DataGrid with procedurally (C#, VS 2010) generated, bound columns, and the DataGrid will not sort data correctly.
CanUserSortColumns is set to true. SortMemberPath is set to the same property as the text displayed in the grid.
Regardless of which column the user sorts, and despite the sort icon being displayed over the appropriate column, the DataGrid merely alternates the sort order of the first column.
column.Header = departmentColumn.ColumnHeader;
column.Width = departmentColumn.ColumnWidth;
column.Binding = new Binding("Cells[" + departmentColumn.Ordinal.ToString() + "]");
column.SortMemberPath = "DisplayString";
I have no problems with any other data being displayed or used incorrectly by the DataGrid, so I am stumped. Why would the sort only consider text in the first column, when everything else binds to data from the appropriate column?