473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagridview Error: At least one of the DataGridView control's columns has no cell te

2 New Member
I created few datagridview columns and then tried to add them to the datagridview columns collection, but got error : At least one of the DataGridView control's columns has no cell template.

Code:
DataGridView dt = new DataGridView();

DataGridViewColumn dt1 = new DataGridViewColumn();
dt1.Name = "col1";
dt1.HeaderText = "col1";

DataGridViewColumn dt2 = new DataGridViewColumn();
dt2.Name = "col2";
dt2.HeaderText = "col2";

dt1.Tag = "sfs";
dt2.Tag = "wer";

dt.Columns.Add(dt1); >> Error occurs here
dt.Columns.Add(dt2);
Mar 1 '11 #1

✓ answered by Singh Harminder

Solution:
We need to define the data type of the column specfically that what kind of data it is going to contain


Code:
DataGridView dt = new DataGridView();

DataGridViewTextBoxColumn dt1 = new DataGridViewTextBoxColumn();
dt1.Name = "col1";
dt1.HeaderText = "col1";

DataGridViewTextBoxColumn dt2 = new DataGridViewTextBoxColumn();
dt2.Name = "col2";
dt2.HeaderText = "col2";

dt1.Tag = "sfs";
dt2.Tag = "wer";

dt.Columns.Add(dt1);
dt.Columns.Add(dt2);

1 10099
Singh Harminder
2 New Member
Solution:
We need to define the data type of the column specfically that what kind of data it is going to contain


Code:
DataGridView dt = new DataGridView();

DataGridViewTextBoxColumn dt1 = new DataGridViewTextBoxColumn();
dt1.Name = "col1";
dt1.HeaderText = "col1";

DataGridViewTextBoxColumn dt2 = new DataGridViewTextBoxColumn();
dt2.Name = "col2";
dt2.HeaderText = "col2";

dt1.Tag = "sfs";
dt2.Tag = "wer";

dt.Columns.Add(dt1);
dt.Columns.Add(dt2);
Mar 1 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: dimension | last post by:
Hi, i have DataGridView whose sourse i set to a datatable with 5 columns containing data. i then remove the 3rd column, created a DataGridViewComboBoxColumn, set it's DataSource, ValueMember and...
1
by: Tom Rahav | last post by:
Hi! My question is if it's possible to adjust DataGrid control's columns' width by code (runtime). I have a DataGrid control that displays table from dataset that contains two fields. The first...
0
by: jwwishart | last post by:
Hi, Weve been doing this sort of thing frequently in ASP.NET but now were working on a project in ASP.NET 2.0 and were having this very strange problem. With the following XHTML... <table...
2
by: news.microsoft.com | last post by:
Hi guys, I have a problem with the DataGridView. I want to catch the value of a cell when the user is editing it. Actually, I can't figure if there is an event or a property to get this value. ...
1
by: Peggy | last post by:
Hi, I wanna list my stocks in a web page according to search result, this listing must be in a (3 columns and unlimited size) table, what I wanna list in a cell is stock name, stock price and...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
0
by: aboobackerpm | last post by:
i am using a binded dgv with datatable my problem is how i can update the changes in a cell of a dgv to datatable without move to next cell my dgv's allow addnew property is false because of...
2
by: Huy Nguyen | last post by:
Hello, How can i force the cell to accept the input for now and flag it as error for user to correct it later. For Example: case 1. I have a column that is NOT bound to database table, then I...
3
nirmalsingh
by: nirmalsingh | last post by:
hai all, How to place a control dynamically in cell of datagridview control?in run time. i am using C#.net(Windows application) thanx in advance with Cheers Nirmal
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.