Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a list containing values list[0]=name, list[1]=id, list[2]=gcghchg ,list[3]=2012

i need to bind the list to datagridview, but list[0], list[1] should be header for datagridview
Posted
Comments
Joan Magnet 27-Mar-15 7:40am    
Build a DataGridView and add a column for each item in the list and use list[] to set the column's caption.

1 solution

Loop through the collection of items in list and add DataGridViewColumn to the DataGredViewColumnCollection[^]. That's all!

Another way is to use AddRange method[^]:
C#
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {stringList.ToArray()});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900