xaml - How can I apply a custom sort rule to a WPF DataGrid? -


When a user sorts a column in my DataGrid , then I will clear all the blank or empty cells

I received a IComparer & lt; T & gt; which ensures that the spaces are always sorted down, but I can not understand how to apply it to my DataGrid column Like the initial , DataGrid , which I'm doing with LINQ OrderBy () method, works great, the problem is that after user's performance Sort all the spaces on top of all types.

Lesson Code

  Public Class Blank Last String Compaq: iComPeerrier & lt; String & gt; {Compare public integer (string x, string y) {if (string. Isnoloracte (x) & string.isnaloractic (y) 1 return; And if (! String.easyallurecti (x) and string. Isnellorecte (y)) return -1; And return string Comparison (X, Y); }}  

Question

How do I get DataGridColumn to use my comparison? Or if this is not possible, can you provide an alternative solution? If possible, I am looking forward to an MVVM friendly solution.

In this way I do it: I get to keep it all inside the grid from the grid, Therefore I attach event handlers internally

related to the sorting event

  datagrid. Sring + = new datagridstring documenthandler (sorthandler);  

Apply the method (I do this in a derived class)

  Zero SortHandler (object sender , DataGridSortingEventArgs e) {DataGridColumn column = E. Column; IComparer balancean = null; // I'm doing some custom testing based on the column to make the correct comparison // There are different comparisons for my different columns. I also handle the // kind direction in my comparison / // sorting To stop the underlying sort Handled = true; ListSortDirection Direction = (column.SortDirection! = ListSortDirection.Ascending)? Listartdirectory Esconding: list separation. Decoding; // Set the sort order on the column column. // Use a ListCollectionView to sort ListCollectionView lcv = (ListCollectionView) ViewSource.GetDefaultView (this.ItemsSource); // This is my custom sorter which gets it from ICMP and has some properties / you can implement the comparison only, but I need to compare some extra bits and pieces I = new ResultSort (direction); // sort lcv.CustomSort = comparer; }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -