how to display datagridview rows as column and columns as rows in another datagridview using datatable
I am using this code but its not working
Dim dts As New DataTable
dts.Columns.Add("SId")
dts.Columns.Add("Shift")
dts.Columns.Add("DDate")
For i = 0 To DataGridView1.Rows.Count - 4
For x = 0 To DataGridView1.Columns.Count - 4
Dim dr As DataRow = dts.NewRow
dr("SId") = DataGridView1.Item(0, i).Value.ToString
dr("DDate") = DataGridView1.Item(2, x).Value.ToString
'dr("Shift") = DataGridView1.CurrentCell.Value.ToString()
'dr("DDate") = DataGridView1.Columns(msg).HeaderText.ToString.ToString()
dts.Rows.Add(dr)
dts.AcceptChanges()
Next
Next
Me.DataGridView2.DataSource = dts
here is what I want
Dim dt1 As DataTable = New DataTable()
dt1.Columns.AddRange(New DataColumn() {New DataColumn("Name"), New DataColumn("01-Jan-18"), New DataColumn("02-Jan-18"), New DataColumn("03-Jan-18"), New DataColumn("04-Jan-18")})
dt1.Rows.Add("Ahemd", "1", "1", "OFF", "OFF")
dt1.Rows.Add("Ajith", "3", "3", "2", "2")
dt1.Rows.Add("Soumya", "OFF", "1", "1", "1")
Me.DataGridView1.DataSource = dt1
Dim dt2 As DataTable = New DataTable()
dt2.Columns.Add("Name")
dt2.Columns.Add("Duty")
dt2.Columns.Add("Date")
dt2.Rows.Add("Ahemd", "1", "01-Jan-2018")
dt2.Rows.Add("Ahemd", "1", "02-Jan-2018")
dt2.Rows.Add("Ahemd", "OFF", "03-Jan-2018")
dt2.Rows.Add("Ahemd", "OFF", "04-Jan-2018")
dt2.Rows.Add("Ajith", "3", "01-Jan-2018")
dt2.Rows.Add("Ajith", "3", "02-Jan-2018")
dt2.Rows.Add("Ajith", "2", "03-Jan-2018")
dt2.Rows.Add("Ajith", "2", "04-Jan-2018")
dt2.Rows.Add("Soumya", "OFF", "01-Jan-2018")
dt2.Rows.Add("Soumya", "1", "02-Jan-2018")
dt2.Rows.Add("Soumya", "2", "03-Jan-2018")
dt2.Rows.Add("Soumya", "3", "04-Jan-2018")
Me.DataGridView2.DataSource = dt2