Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 4.25 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-09-2006, 10:28 PM   PM User | #1
Melon00
Regular Coder

 
Join Date: Mar 2006
Location: Ames, IA
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Melon00 is an unknown quantity at this point
Question [c#] Dynamically adding rows to DataGridView

I am using a DataGridView in my app. How do I add a new row to the already existing dataset?

I see tons of web control stuff, but nothing on window forms...

I attempted this code
dataGridView1.Rows.Add(new string());

When I run this code, it is giving the following exception:

exception: rows cannot be added programatically to the datagridview's collection when control is databound.

Tell me there is a way to add rows to a DataGridView dynamically, since you can in C++.
Melon00 is offline   Reply With Quote
Old 06-15-2006, 06:26 PM   PM User | #2
Melon00
Regular Coder

 
Join Date: Mar 2006
Location: Ames, IA
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Melon00 is an unknown quantity at this point
Figured it out...

Code:
DataRow dr;
DataSet ds; // this is bound to DataGridView

// some logic setting up dataset and tables within

dr = ds.Tables[0].NewRow(); // Table[0] of ds is the data I want to display
dr["Column1"] = "Finally";
dr["Column2"] = "Got";
dr["Column3"] = "this";
dr["Column4"] = "Working";

// add row to dataset now
ds.Tables[0].Rows.Add(dr);

Last edited by Melon00; 06-15-2006 at 06:31 PM..
Melon00 is offline   Reply With Quote
Old 08-25-2010, 09:13 AM   PM User | #3
robertsams23
New Coder

 
Join Date: Mar 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
robertsams23 is an unknown quantity at this point
The following link will help u

http://csharp.net-informations.com/d...w-tutorial.htm

rob.
robertsams23 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 PM.


Advertisement
Log in to turn off these ads.