Click here to Skip to main content
15,798,592 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";
          column2 = new DataGridViewColumn();
          column2.DataPropertyName = "Name";
          column2.Name = "Name";
          column3 = new DataGridViewColumn();
          column3.DataPropertyName = "RegNum";
          column3.Name = "Registration Number";
          column4 = new DataGridViewColumn();
          column4.DataPropertyName = "Gender";
          column4.Name = "Gender";
          column5 = new DataGridViewColumn();
          column5.DataPropertyName = "Relationship";
          column5.Name = "Relationship";
          column6 = new DataGridViewColumn();
          column6.DataPropertyName = "Address";
          column6.Name = "Address";

Any help is much appreciated!

Updated 12-Jul-23 18:36pm

I thought use a list is best way, you can try it
Share this answer
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
Ahsan Mirza 21-Jun-11 2:04am    
Thanks bro!
Read this
Share this answer
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