Here is more correct code (in previous example sorting performed on old SortOrder of column, but if we use sorting in ColumnSortOrderChanging we should use new SortOrder value):
[c#]
private void SortNodes(NodeBase node, Column col, SortOrder newOrder)
{
NodesComparer comparer = new NodesComparer(col, newOrder);
node.Items.Sort(comparer);
}
public class NodesComparer : IComparer
{
private Column col;
private SortOrder order;
public NodesComparer(Column col, SortOrder order)
{
this.col = col;
this.order = order;
}
#region IComparer Members
public int Compare(object x, object y)
{
Node xnode = x as Node;
Node ynode = y as Node;
int result = 0 ;
object xobj = xnode.GetCellValue(col);
object yobj = ynode.GetCellValue(col);
IComparable xvalue = xobj as IComparable;
IComparable yvalue = yobj as IComparable;
if (xvalue != null && order == SortOrder.Ascending)
{
result = xvalue.CompareTo(yvalue);
}
else if (yvalue != null && order == SortOrder.Descending)
{
result = yvalue.CompareTo(xvalue);
}
return result;
}
#endregion
}