Answered by:
How to bind datatable/list to datagridview with headers?

Question
-
The datagridview at design time as below:
After I bind a list to datagridview the result as below:
I want the data is showed under columns 0,1,2,3,4 of datagridview, not add more columns
Please help me,
Thanks, Dai Nguyen Quang.
- Moved by CoolDadTx Sunday, July 29, 2012 2:23 AM Winforms related (From:Visual C# General)
Saturday, July 28, 2012 9:14 PM
Answers
-
DataGridViewColumn has a property called DataPropertyName which in you case need to be set as your column name. You are creating your columns through designer hence you can access this property through the designer property window.
Alternately you can access through code (if needed) . Ref
// Initialize and add a text box column. DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Title"; column.Name = "clTitle"; dataGridView1.Columns.Add(column);
If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.
Regards,
Nair S- Marked as answer by Chester Hong Thursday, August 2, 2012 8:45 AM
Saturday, July 28, 2012 11:22 PM
All replies
-
DataGridViewColumn has a property called DataPropertyName which in you case need to be set as your column name. You are creating your columns through designer hence you can access this property through the designer property window.
Alternately you can access through code (if needed) . Ref
// Initialize and add a text box column. DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Title"; column.Name = "clTitle"; dataGridView1.Columns.Add(column);
If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.
Regards,
Nair S- Marked as answer by Chester Hong Thursday, August 2, 2012 8:45 AM
Saturday, July 28, 2012 11:22 PM -
My problem was solved, thanks so much.
Dai Nguyen Quang.
Sunday, July 29, 2012 2:41 PM -
My problem was solved, thanks so much.
Dai Nguyen Quang.
If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.
Regards,
Nair SMonday, July 30, 2012 8:45 AM -
Hi Quang, May you help me in this issue? I do the same but it's not solved!Thursday, May 18, 2017 1:25 AM