Hi
I am trying to have sort functionality on Ultra Win Grid on column header click. The problem is I want it to sort by Natural sort order. The field type is string.
Do we have Natural sort order functionality in UltraWinGrid?
Thanks
Oh, okay. Now i know what you mean.
The grid already sorts strings alphabetically. But if you want strings that contain numbers to be sorted by their numeric values, you would need a SortComparer for that.
That should be a very easy SortComparer, though. All you have to do is get the text of each cell and use string.CompareOrdinal.
public class OrdinalSortComparer : IComparer { int IComparer.Compare(object x, object y) { UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; /// Sanity checks if (xCell == yCell) return 0; if (null == xCell) return 1; if (null == yCell) return -1; string xText = xCell.Text; string yText = yCell.Text; return string.CompareOrdinal(xText, yText); } }
Hi Mike,
Thanks I will implement the Natural sort.
Natural sort is like if we have string data column and want to sort in numeric order for numbers and alphabetic order for words.
e.g. values are: 1 , 3, 10, abc
String (alphabetic) order would be: 1, 10, 3, abc; but Natural sort order would be: 1, 3, 10 , abc
Hi,
I don't know what you mean by "Natural sort order". But if you want to sort by anything other than the default, you would have to use a SortComparer on the column. You create a class that implements the IComparer interface and then you can control the sort order in whatever way you like.