C# - How can i get header row from datatable and arrange it vertically down a column?
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;
}
c# visual-studio visual-studio-2013 datagridview datatable
add a comment |
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;
}
c# visual-studio visual-studio-2013 datagridview datatable
add a comment |
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;
}
c# visual-studio visual-studio-2013 datagridview datatable
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;
}
c# visual-studio visual-studio-2013 datagridview datatable
c# visual-studio visual-studio-2013 datagridview datatable
edited Jun 17 '16 at 4:23
MRu
asked Jun 17 '16 at 4:14
MRuMRu
175319
175319
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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();
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
add a comment |
Simply set the Header to be visible like this:
DataGridView.ColumnHeaderVisible = true;
This worked for me.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37873023%2fc-sharp-how-can-i-get-header-row-from-datatable-and-arrange-it-vertically-down%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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();
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
add a comment |
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();
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
add a comment |
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();
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();
answered Jun 17 '16 at 4:29
SamiSami
2,1412820
2,1412820
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
add a comment |
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
1
1
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
I think it returns the length of the column. But it did change to vertically down a column. Can i know. Is this what they call LINQ?
– MRu
Jun 17 '16 at 4:39
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
Yes, this is LINQ . will return ColumnName and if you bind with Grid, will be shown vertically as needed.
– Sami
Jun 17 '16 at 4:43
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
the columnNames did store the row values in array. But when i set it to dataGridView1.DataSource it shows the property of the array. Not the values in it. Can i know how i can solve this?
– MRu
Jun 17 '16 at 6:42
add a comment |
Simply set the Header to be visible like this:
DataGridView.ColumnHeaderVisible = true;
This worked for me.
add a comment |
Simply set the Header to be visible like this:
DataGridView.ColumnHeaderVisible = true;
This worked for me.
add a comment |
Simply set the Header to be visible like this:
DataGridView.ColumnHeaderVisible = true;
This worked for me.
Simply set the Header to be visible like this:
DataGridView.ColumnHeaderVisible = true;
This worked for me.
answered Dec 31 '18 at 18:56
Kovacs LaszloKovacs Laszlo
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37873023%2fc-sharp-how-can-i-get-header-row-from-datatable-and-arrange-it-vertically-down%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown