473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

datagridview


I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.

But when I add the column I got this error:

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

Can someone help me?

I want to add something like this:

Name Id Balance
ABC 123 300
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jul 17 '08 #1
4 12138
On Jul 17, 5:36*am, Claudia Fong <cdolphi...@yahoo.co.ukwrote:
I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.

But when I add the column I got this error:

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

Can someone help me?

I want to add something like this:

Name * * Id * * Balance
ABC * * *123 * * 300 * * *

Cheers!

* * Claudi

*** Sent via Developersdexhttp://www.developersdex.com***
I don't know what you mean by 'manually'? You mean by hand, or by
code?

If by code or by hand, just start from scratch. Somewhere you have a
self-referential pointer that points back to itself and throws you for
a loop. Stuff is binding to stuff that is also trying to bind and you
have this back and forth situation--pardon my scientific language.

My two cents, for what it's worth.

RL
Jul 17 '08 #2
Claudia:

First, your DataGridView has to be "unbound."

If that is the case, here is a snippet that might get you going:

foreach (DataRow row in DataSet1.Tables[tableName].Rows) {
DataGridViewRow dgRow = new DataGridViewRow();
dgRow.CreateCells(DataGridView1);
object[] obj = row.ItemArray;
for (int j = 0; j < obj.Length; j++) {
dgRow.Cells[j].Value = string.Format("{0}", obj[j]);
}
DataGridView1.Rows.Add(dgRow);
dgRow = null;
}
DataGridView1.AutoResizeColumns(DataGridViewAutoSi zeColumnsMode.AllCells);

Hope that helps!
"Claudia Fong" wrote:
>
I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.

But when I add the column I got this error:

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

Can someone help me?

I want to add something like this:

Name Id Balance
ABC 123 300
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jul 17 '08 #3
Try this:

//Add the first column
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Name";
col.ValueType = typeof(String);
dataGridView1.Columns.Add(col);
//Add the second column
col = new DataGridViewTextBoxColumn();
col.HeaderText = "Id";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
//Add the third column
col = new DataGridViewTextBoxColumn();
col.HeaderText = "Id";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);

//add the data
dataGridView1.Rows.Add("ABC", 123, 300);

//auto size the columns to make them pretty
dataGridView1.AutoResizeColumns(DataGridViewAutoSi zeColumnsMode.AllCells);
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Claudia Fong" wrote:
>
I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.

But when I add the column I got this error:

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

Can someone help me?

I want to add something like this:

Name Id Balance
ABC 123 300
Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jul 18 '08 #4
What you have written makes absolutely no sense at all.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"raylopez99" wrote:
On Jul 17, 5:36 am, Claudia Fong <cdolphi...@yahoo.co.ukwrote:
I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.

But when I add the column I got this error:

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

Can someone help me?

I want to add something like this:

Name Id Balance
ABC 123 300

Cheers!

Claudi

*** Sent via Developersdexhttp://www.developersdex.com***

I don't know what you mean by 'manually'? You mean by hand, or by
code?

If by code or by hand, just start from scratch. Somewhere you have a
self-referential pointer that points back to itself and throws you for
a loop. Stuff is binding to stuff that is also trying to bind and you
have this back and forth situation--pardon my scientific language.

My two cents, for what it's worth.

RL
Jul 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
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...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.