Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i add columns to a data grid, i get this error.

At least one of the DataGridView control's columns has no cell template.

Why is this happening?

Any idea?

Code to add new columns is:

dataGridView1.AutoGenerateColumns = false;
          DataGridViewColumn column1;
          DataGridViewColumn column2;
          DataGridViewColumn column3;
          DataGridViewColumn column4;
          DataGridViewColumn column5;
          DataGridViewColumn column6;
          column1 = new DataGridViewColumn();
          column1.DataPropertyName = "ID";
          column1.Name = "ID";
          dataGridView1.Columns.Add(column1);
          column2 = new DataGridViewColumn();
          column2.DataPropertyName = "Name";
          column2.Name = "Name";
          dataGridView1.Columns.Add(column2);
          column3 = new DataGridViewColumn();
          column3.DataPropertyName = "RegNum";
          column3.Name = "Registration Number";
          dataGridView1.Columns.Add(column3);
          column4 = new DataGridViewColumn();
          column4.DataPropertyName = "Gender";
          column4.Name = "Gender";
          dataGridView1.Columns.Add(column4);
          column5 = new DataGridViewColumn();
          column5.DataPropertyName = "Relationship";
          column5.Name = "Relationship";
          dataGridView1.Columns.Add(column5);
          column6 = new DataGridViewColumn();
          column6.DataPropertyName = "Address";
          column6.Name = "Address";
          dataGridView1.Columns.Add(column6);


Any help is much appreciated!

Thanks!
Posted
Updated 12-Jul-23 17:36pm

I thought use a list is best way, you can try it
 
Share this answer
 
Comments
Richard Deeming 13-Jul-23 3:14am    
Check the date on the question. It only came back into the "active" list thanks to the idiot posting abuse in solution 3.
Try Google with your error message and then you might be able to find this link. I believe this will resolve your problem.
 
Share this answer
 
Comments
Ahsan Mirza 21-Jun-11 2:04am    
Thanks bro!
Read this http://www.wpftutorial.net/DataGrid.html
 
Share this answer
 
v3
Comments
Ahsan Mirza 21-Jun-11 2:55am    
i was actually looking for windows application!

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