C# - How can i get header row from datatable and arrange it vertically down a column?
17,271
Try
string[] columnNames = dt.Columns.Cast<DataColumn>()
.Select(x => x.ColumnName)
.ToArray();
dataGridView1.DataSource = columnNames;
Or
dataGridView1.DataSource = dt.Columns.Cast<DataColumn>()
.Select(x => x.ColumnName)
.ToArray();
Author by
MRu
i'm technically new in programming with limited knowledge on IT. But i'm willing to learn. So bare with me please
Updated on June 11, 2022Comments
-
MRu almost 2 years
How can i turn this datagridview from datatable
Here is my code now. Any suggestion, comments, or sample code are highly appreciated. Thank you.
DataSet result = excelReader.AsDataSet(); excelReader.Close(); if (result != null) { DataTable dataTable = result.Tables[0]; List<string> headers = new List<string>(); foreach (DataColumn col in dataTable.Columns) { headers.Add(col.ColumnName); } dataGridView1.DataSource = dataTable; }