Home > DeveloperSection > Forums > c# How to add a new row to datagridview programmatically?
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    November-14-2013 1:03 AM

 C# C# 
Ratings:


 1 Reply(s)
 9251  View(s)
Rate this:
I have a datagridview and I want to add a new row to datagridview programatically.How to achieve this? 


Pravesh Singh

Total Post:411

Points:2881
Posted on    November-14-2013 1:16 AM

Hi takeshi,

You can try like this:

 dataGridView1.Columns[0].Name = "column2";

 dataGridView1.Columns[1].Name = "column6";

 string[] row1 = new string[] { "column2 value", "column6 value" };

 dataGridView1.Rows.Add(row1);

Or you need to set there values individually use the propery .Rows(), like this:

 dataGridView1.Rows[1].Cells[0].Value = "cell value";


Don't want to miss updates? Please click the below button!

Follow MindStick