How to Add a Row in DataGridView

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Add a Row in DataGridView
DataGridView control allows users to add rows on Windows Forms. (Jupiterimages/ Images)

The DataGridView control of Microsoft .NET Framework creates an editable table for displaying user data. It uses properties of the cells, rows and columns to represent table data on Windows Forms. Setting the DataSource and DataMember properties binds the DataGridView control to a data source and fills it out with data. The use of the Row collection allows users to populate a DataGridView control manually instead of binding it to a data source. You need to apply the AddNew method to the Row collection in order to add a row in DataGridView .NET Framework control.

Skill level:

Other People Are Reading


  1. 1

    Click the "Start" button in Windows and select the "Microsoft Visual Studio".

  2. 2

    Click the "Open" and select C++ program in which you want to add a row in DataGridView control.

  3. 3

    Add the following code after the "AutoAddNewRow: Form" line in your C program:

        public AutoAddNewRow()
        DataTable dt = new DataTable();
        private void AutoAddNewRow_Load(object sender, EventArgs e)
            dt.Columns.Add("c", typeof(bool));
            for (int j = 0; j < 10; j++)
                dt.Rows.Add("a" + j.ToString(), "escddf", j % 2 == 0);
            this.dataGridView1.DataSource = dt;
        private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
            e.Row.Cells["a"].Value = "needa";
            e.Row.Cells["b"].Value = "needb";
            e.Row.Cells["c"].Value = true;
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
            if (e.RowIndex == this.dataGridView1.NewRowIndex)
                string value = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();


  4. 4

    Click the "File," "Save" to add a row in DataGridView control of your C++ program.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.