Sort by Contains

Is there a way to sort in ascending for a column that contains rows with plus signs ("+")?
As in there are also rows without pluses but I just want to give priority to the ones with plus signs.

If you want the + columns on top you need use sort descending since you are going to use contains function.

Assign:

yourDataTable = yourDataTable.AsEnumerable.OrderByDescending(Function(row) row("YouColumnName").ToString.Contains("+")).CopyToDataTable()

Note: Check if your data table has rows before using the above code since CopyToDataTable will generate an exception if there is no rows.

Hey thanks for the response, could you rewrite that into C#?

bump

Hi,

In C#:

yourDataTable = yourDataTable.AsEnumerable().OrderByDescending(row => row["YourColumnName"].ToString().Contains("+")).CopyToDataTable();
1 Like

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