c# How to add a new row to datagridview programmatically?

Total Post:89

Points:629

C# 
C#
 15294  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. 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";

      Modified On Apr-03-2018 05:54:04 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.