Public Function SwapTable(ByRef dt As DataTable, ByVal col As Integer) As DataTable
Try
Dim dtTemp As New DataTable
Dim inti, intj As Integer
dtTemp.Columns.Clear()
dtTemp.Columns.Add(dt.Columns(col).Caption)
For inti = 0 To dt.Columns.Count - 1
If inti = col And inti  0 Then
'If dt.Columns(0).Caption.Trim  "DC_NOHID" Then
dtTemp.Columns.Add(dt.Columns(0).Caption)
'Else
' dtTemp.Columns.Add(dt.Columns(1).Caption)
'End If
End If
If inti  col And inti  0 Then
dtTemp.Columns.Add(dt.Columns(inti).Caption)
End If
Next
Dim Dr As DataRow
For intj = 0 To dt.Rows.Count - 1
Dr = dtTemp.NewRow
Dr.Item(0) = dt.Rows(intj).ItemArray(col)
Dr.Item(col) = dt.Rows(intj).ItemArray(0)
inti = 1
While inti < dt.Columns.Count
If inti  0 And inti  col Then
Dr.Item(inti) = dt.Rows(intj).ItemArray(inti)
End If
inti += 1
End While
dtTemp.Rows.Add(Dr)
Next
dt.Clear()
dt = dtTemp.Copy
For inti = 0 To dt.Columns.Count - 1
dt.Columns(inti).ReadOnly = True
dt.DefaultView.Sort = dt.Columns(0).ColumnName
Next
Return dt
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Msg")
End Try
End Function

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments