ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Convert DataGridView rows as columns in Windows Application<p>Hi <a class="username" rel="satabeach">satabeach</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">DataTable dt1 = new DataTable(); DataTable dt2 = new DataTable(); public Form1() { InitializeComponent(); dt1.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Name&#34;), new DataColumn(&#34;01-Jan-18&#34;), new DataColumn(&#34;02-Jan-18&#34;), new DataColumn(&#34;03-Jan-18&#34;), new DataColumn(&#34;04-Jan-18&#34;) }); dt1.Rows.Add(&#34;Ahemd&#34;, &#34;1&#34;, &#34;1&#34;, &#34;OFF&#34;, &#34;OFF&#34;); dt1.Rows.Add(&#34;Ajith&#34;, &#34;3&#34;, &#34;3&#34;, &#34;2&#34;, &#34;2&#34;); dt1.Rows.Add(&#34;Soumya&#34;, &#34;OFF&#34;, &#34;1&#34;, &#34;1&#34;, &#34;1&#34;); this.DataGridView1.DataSource = dt1; } private void Button1_Click(object sender, EventArgs e) { dt2.Columns.Add(&#34;Name&#34;); dt2.Columns.Add(&#34;Duty&#34;); dt2.Columns.Add(&#34;Date&#34;); for (int row = 0; row &lt; dt1.Rows.Count; row++) { for (int column = 1; column &lt; dt1.Columns.Count; column++) { dt2.Rows.Add(dt1.Rows[row][0], dt1.Rows[row][column], dt1.Columns[column].ColumnName); } } DataGridView1.DataSource = dt2; }</pre> <p><strong>&nbsp;VB.Net</strong> </p> <pre class="brush: vb">Private dt1 As DataTable = New DataTable() Private dt2 As DataTable = New DataTable() Public Sub New() InitializeComponent() dt1.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Name&#34;), New DataColumn(&#34;01-Jan-18&#34;), New DataColumn(&#34;02-Jan-18&#34;), New DataColumn(&#34;03-Jan-18&#34;), New DataColumn(&#34;04-Jan-18&#34;)}) dt1.Rows.Add(&#34;Ahemd&#34;, &#34;1&#34;, &#34;1&#34;, &#34;OFF&#34;, &#34;OFF&#34;) dt1.Rows.Add(&#34;Ajith&#34;, &#34;3&#34;, &#34;3&#34;, &#34;2&#34;, &#34;2&#34;) dt1.Rows.Add(&#34;Soumya&#34;, &#34;OFF&#34;, &#34;1&#34;, &#34;1&#34;, &#34;1&#34;) Me.DataGridView1.DataSource = dt1 End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) dt2.Columns.Add(&#34;Name&#34;) dt2.Columns.Add(&#34;Duty&#34;) dt2.Columns.Add(&#34;Date&#34;) For row As Integer = 0 To dt1.Rows.Count - 1 For column As Integer = 1 To dt1.Columns.Count - 1 dt2.Rows.Add(dt1.Rows(row)(0), dt1.Rows(row)(column), dt1.Columns(column).ColumnName) Next Next DataGridView1.DataSource = dt2 End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/OwbUSiF.gif" alt="" width="472" height="316" /></p>https://www.aspforums.net:443/Threads/104847/Convert-DataGridView-rows-as-columns-in-Windows-Application/https://www.aspforums.net:443/Threads/104847/Convert-DataGridView-rows-as-columns-in-Windows-Application/Fri, 19 Oct 2018 05:48:09 GMT