Sorting Strings as Numbers

In the .NET Platform, strings are not compared like numbers. For example, the string "100" is less than the string "2" because it compares strings in alphabetic order.

One possible solution would be the use of IComparable as illustrated in the Custom Sorting with IComparable demo.

As another option, you can expose a property of the business object to hold the numeric value and set it as SortMemberPath of the column. That way the column will be sorted by this numeric property and not by the string property specified as DataMemberBinding (applies to ColumnSortDescriptor only).

For more detailed information on the sorting mechanism, you can check the Sorting section.

See Also

In this article