I need to sort DataTables, however the sort-by-columns vary.
Scenario #1, DataTable1 should be sorted by "Column1".
Scenario #2, DataTable2 should be sorted by "Column1, Column2".
Below is my first attempt at creating a helper function for this purpose. This works ok.
Private Sub SortDataTable(ByRef dataTable As DataTable, ByVal sortColumnNames As List(Of String))
'Validation (not shown here)
Dim sortOrder = String.Join(", ", sortColumnNames)
dataTable.DefaultView.Sort = sortOrder
dataTable = dataTable.DefaultView.Table
End Sub
I tried implementing this in LINQ, however, I don't know how to pass multiple sort-by-columns to the lambda function. Work-in-progress code shown below.
Private Sub SortDataTable(ByRef dataTable As DataTable, ByVal sortColumnNames As List(Of String))
'Validation (not shown here)
dataTable.AsEnumerable().OrderBy(Function (row) row(sortColumnNames(0))).ThenBy(...)
End Sub
How should I pass multiple sort-by-columns to the OrderBy/ThenBy extension methods?