hi
I,m working with grid and used :
grid.Grid.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle;
but when click the header not sorted correctly
What do you mean by "not sorted correctly?" What's wrong with it?
for example:
before sorting: 90
98
51
978
after sorting:51
90
It sounds like data type for that colums is String and sorting is performed for strings.
Try to set numeric type.
Alex.
thanks a lot
1. Create comparer.
private class CustomComparer : IComparer { int IComparer.Compare(object x, object y) { UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; double val1; double val2; double.TryParse(xCell.Value.ToString(), out val1); double.TryParse(yCell.Value.ToString(), out val2); return val1.CompareTo(val2); }
2. Set it to column:
UltraGridColumn valueCol = grid_.DisplayLayout.Bands[0].Columns["Value"]; valueCol.SortComparer = new CustomComparer();
See small attached project for more details. Column "Value" has string type but it's sorted as numeric.
pleaze help me for using a Sortcomparer by example
thanks
Yeah, Alex is right. Your column must be storing numeric values in a String column. So the strings gets sorted alphabetically instead of numerically. You should make sure the column is a numeric type. Or, if that's not possible, you can use a SortComparer to convert the strings to numbers and sort them that way.