954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add a new row to a datagrid

Hi,
Can anybody help me to add a blank row into a datagrid?
Thank you!

menelaussa
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

DGV.Rows.add();

But if the datagrid is binded you need to add the row to the datasource, NOT in the DGV

DataTable.rows.add();

olibara
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
DGV.Rows.add();

But if the datagrid is binded you need to add the row to the datasource, NOT in the DGV

DataTable.rows.add();
olibara
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Could I enquire as to why you would want to do this? Give this a try:

datagrid1.Rows.Add(new object[]{null,null});

I am not sure if this will work but give it a try - let me know how it goes!

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Thank you to all for your answers.
My datagrid is binded to an object.
I am adding an new empty collection to the object before to bind it to the datagrid.
I have a new empty row into my datagrid, but now the problem is that the id the item is null and I cannot update or delete it.

Can you help me with that?

Thank you!

menelaussa
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Hooraay , I added a new object on Update and Delete procedures and now it works fine.
Thank you for your replay!

menelaussa
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

What object ?
What Id
What code

Difficult to say anything without a little more details ..

olibara
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Set the all property of datagrid

sanjayNawab
Newbie Poster
4 posts since May 2008
Reputation Points: 10
Solved Threads: 2
 

BindingContext[datasetname,"table"].newrow();

o_shawky
Newbie Poster
6 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You