User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 373,189 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,812 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 775 | Replies: 8
Reply
Join Date: May 2008
Posts: 15
Reputation: menelaussa is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
menelaussa menelaussa is offline Offline
Newbie Poster

How to add a new row to a datagrid

  #1  
May 13th, 2008
Hi,
Can anybody help me to add a blank row into a datagrid?
Thank you!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2008
Posts: 7
Reputation: olibara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
olibara olibara is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #2  
May 13th, 2008
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();
Reply With Quote  
Join Date: May 2008
Posts: 7
Reputation: olibara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
olibara olibara is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #3  
May 13th, 2008
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();
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 46
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: How to add a new row to a datagrid

  #4  
May 13th, 2008
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!
Last edited by majestic0110 : May 13th, 2008 at 5:26 pm.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: May 2008
Posts: 15
Reputation: menelaussa is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
menelaussa menelaussa is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #5  
May 14th, 2008
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!
Reply With Quote  
Join Date: May 2008
Posts: 15
Reputation: menelaussa is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
menelaussa menelaussa is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #6  
May 14th, 2008
Hooraay , I added a new object on Update and Delete procedures and now it works fine.
Thank you for your replay!
Reply With Quote  
Join Date: May 2008
Posts: 7
Reputation: olibara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
olibara olibara is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #7  
May 14th, 2008
What object ?
What Id
What code

Difficult to say anything without a little more details ..
Reply With Quote  
Join Date: May 2008
Posts: 4
Reputation: sanjayNawab is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
sanjayNawab sanjayNawab is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #8  
May 15th, 2008
Set the all property of datagrid
Reply With Quote  
Join Date: Jan 2008
Posts: 6
Reputation: o_shawky is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
o_shawky o_shawky is offline Offline
Newbie Poster

Re: How to add a new row to a datagrid

  #9  
May 19th, 2008
BindingContext[datasetname,"table"].newrow();
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 9:52 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC