I have a WPF Datagrid with custom sorting and it works great. I need to lock some entries in the collection to Top and Bottom (Top Lock and Bottom Lock). Therefore, when a particular record is locked at the top, it should be the first record in the collection, regardless of any value for the selected column (i.e., I do not want to sort those rows that are locked at the top and bottom). Here is my sorting method.
private void PerformLineCustomSort(DataGridColumn column)
{
ListSortDirection direction = (column.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending;
column.SortDirection = direction;
ListCollectionView listCollectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(Lines);
LineSorter lineSort = new LineSorter(direction, column);
listCollectionView.CustomSort = lineSort;
}
where LineSorter is my custom sorter class with IComparer implementation . It works great. Now I want to apply Top Lock and Bottom lock to the ListCollectionView. I tried the following code with the above, but it has no changes (i.e. the List is sorted based on only a custom sort column).
listCollectionView.SortDescriptions.Add(new SortDescription("TopLock", ListSortDirection.Descending));
listCollectionView.SortDescriptions.Add(new SortDescription("BotLock", ListSortDirection.Ascending));
Is there a way to make this script or do I need to manually delete and then add the locked records. Please suggest ..
source
share