Hi,
I want to use Excel-style soring for my text column so that it sorts values as 1,2,..10,11 instead of 1,10..2,20.. as would be the default for test sorting.
Thanks in advance
Regards
Habib
You have two options.
The first and easiest is to use a numeric datatype, such as int or double, for the data in the underlying grid column. By default, the grid will sort using the IComparable implementation of the data type, so numbers get sorted as numbers and strings as strings.
The other way, more powerful but requiring more code to accomplish, is to implement your own SortComparer. The API documentation for the SortComparer property of the UltraGridColumn class (from the online help documentation for NetAdvantage for .NET 2008 Volume 3) provides more detail and a simple example implementation.
Thanks for the answer. I implemented a SortComparer , as below.
public class SortComparer : IComparer
{
}
// Passed in objects are cells. So you have to typecast them to UltraGridCell objects first.
UltraGridCell yCell = (UltraGridCell)y;
// convert the compared values to string
// if both values are numeric, compare as numeric; if one them is numeric bump it up; else compare as string
decimal Num2;
decimal.TryParse(text2, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out Num2);
else
double retNum;
I have the values as 1,2,3,...9,10.11...20 etc and T1,T2,T3.......I want to sort as 1,2,..9,10,11,12.. etc following with T1,T2,T3...
please advice.
Thanks!!!
Lal
Thanks for your reply.I implemented as you said and got it!!!
Thank you!!!
Lal,
To get the results you've described, you will need to implement a SortComparer as detailed earlier in this thread.