Diogo said:
Greetings,
I am trying to sort this values on a datatable
1
2
12rw
3
12r
4v
10a
e1
1w3
This was suposed to be sorted like this
1
1w3
2
3
4v
10a
12r
12rw
e1
I can't find a solution to sort this way.
Can anyone help me?
Assuming these "values" are strings, you will have to define the custom rule by
which they are to be ordered. You don't show the actual result you obtained,
but the default would be lexicographic order, which would come out as:
1, 10a, 12r, 12rw, 2, 3, 4v, e1
One way to define your own order would be to define a class which wraps each
string in an class instance, and then implement IComparable on the class. This
may not be easy in your case at hand. Your desired ordering is not (to me, at
least) intuitive. I would have guessed that "e1" would come first, not last,
for example, given the rest of your apparent pattern, which appears to be
something like "numeric part followed by alphanumeric part".
Basically it comes down to whether you can implement IComparable in a way which
gives the correct relative order of any two items in all cases. If not, then
your sort order is not well enough defined. It is tough to tell from your example.
HTH,
-rick-