Datatable sort


I would need to sort a datatable for a specific column: “Column1”

The rules I should follow are as follows:

  • First only the numericals, in ascending order
  • Then the alphanumerics, in ascending order (ex. 100a - 100b - 101a)
  • Then those containing only letters, in ascending order

Is it possible to handle this casuistry via a linq? In what way?

Thank you (13.8 KB)
Please download and run hopefully it is what you want

Thanks for the help, but…

this is the expected result



How about the following?

dt = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,"^\d+$")).OrderBy(Function(r) Double.Parse(r(0).ToString)).Concat(dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,"[A-Za-z]") AndAlso System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,"\d") AndAlso System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,"^[0-9A-Za-z]+$")).OrderBy(Function(r) r(0).ToString)).Concat(dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,"^[A-Za-z]+$")).OrderBy(Function(r) r(0).ToString)).CopyToDataTable (2.8 KB)


1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.