Category Archives: VB

[VB] change row and column


Public Function PivotTable(ByVal  As DataTable) As DataTable
 Dim dest As New DataTable("Pivoted" + .TableName)

 dest.Columns.Add(" ")

 Dim r As DataRow
 For Each r In .Rows
 dest.Columns.Add(r(0).ToString())
 Next r
 Dim i As Integer
 For i = 0 To (.Columns.Count - 1) - 1
 dest.Rows.Add(dest.NewRow())
 Next i

 For i = 0 To dest.Rows.Count - 1
 Dim c As Integer
 For c = 0 To dest.Columns.Count - 1
 If c = 0 Then
 dest.Rows(i)(0) = .Columns((i + 1)).ColumnName
 Else
 dest.Rows(i)(c) = .Rows((c - 1))((i + 1))
 End If
 Next c
 Next i
 dest.AcceptChanges()
 Return dest
 End Function 'PivotTable

출처: http://aspalliance.com/538_CodeSnip_Pivot_Tables_with_ADONET_and_Display_in_a_DataGrid_Paged_Horizontally