C# HOW TO ADD A NEW ROW TO DATAGRIDVIEW PROGRAMMATICALLY?

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
C# 
C#
 13819  View(s)
Ratings:
Rate this:
I have a datagridview and I want to add a new row to datagridview programatically.How to achieve this? 
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: c# How to add a new row to datagridview programmatically?

    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";

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!