How can i turn this datagridview from datatable
into this
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;
}
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With