Hi I need help to do a sorting on a DataTable

Hi guys ,
i need your help to a custom sorting based on "if the row have value of “ME” then it will go up in the sorting but not go in the first row more like it will be get stacked one by one then the other will fill in "

example

image

Please let me know if you have any suggion to do it ya

thank you very much
Regards
Ahmad

Hi @Ahmad_Rais

If this is the only input case, then you can sorting it directly using OrderBy function:

yourDt.AsEnumerable.OrderBy(Function(row) row("Product").ToString).CopyToDataTable

image

Best Regards.

Hi,

How about the following expression? This put rows which contains “ME” first then remaining.

dt = dt.AsEnumerable.OrderByDescending(Function(r) r("product").ToString.Contains("ME")).ThenBy(Function(r) r("product").ToString).CopyToDataTable

Sample20230519-6L.zip (8.3 KB)

Regards,

2 Likes

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