Private Sub SortTable(ByVal dt As DataTable, ByVal col As DataColumn)
Dim SortValues(dt.Rows.Count - 1) As Object
Dim SortIndex(dt.Rows.Count - 1) As Integer
For i As Integer = 0 To dt.Rows.Count - 1
SortIndex(i) = i
SortValues(i) = dt.Rows(i)(col)
Next
System.Array.Sort(SortValues, SortIndex)
For i As Integer = 0 To SortIndex.GetUpperBound(0)
dt.ImportRow(dt.Rows(SortIndex(i)))
Next
For i As Integer = 0 To SortIndex.GetUpperBound(0)
dt.Rows.RemoveAt(0)
Next
End Sub
Is this not more simple?
\\\
Dim dv As New DataView(dt)
dv.Sort = "bla"
Dim dtnew As DataTable = dt.Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow(dvr.Row)
Next
///
Yes, certainly. But I ran into the problem of already having variables
pointing to columns in the original table so I couldn't use a newly created
one. I would definitely use your solution otherwise.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.