Home Forums WinForms controls Xceed Grid for WinForms Sorting Question Reply To: Sorting Question

User (Old forums)
Member
Post count: 23064

You can create a custom comparer, that compares the numeric values of the strings, and assign it to the <b>DataComparer</b> property of the column. Such a custom comparer is just a class that implements the <b>IComparer</b> interface and has a method <b>Compare</b>. Like this:
<code>public class myComparer : System.Collections.IComparer
{
int IComparer.Compare(object x, object y)
{
try
{
int ix = Convert.ToInt32(x);
int iy = Convert.ToInt32(y);

if (ix < iy) then return -1;
else if (ix > iy) then return 1;
else return 0;
}
catch(Exception ex)
{
throw new ArgumentException(“Can’t compare arguments”);
}
}
}</code>
Then you can assign your comparer to the column:
<code>myGrid.Columns[“myColumn”].DataComparer = new myComparer();</code>

Imported from legacy forums. Posted by Tommy (had 3064 views)