SoFunction
Updated on 2025-03-07

Datagridview implements manual addition of row data

datagridview manually add row data

When I was working on the software model interface, I triggered the displayed datagridview through the function button. For convenience, I needed some data and just wrote dead data. Therefore, there is no need to connect to the data table, just add rows.

The code is as follows:

        int index = this.();
        this.[index].Cells[0].Value = "1";
        this.[index].Cells[1].Value = "11";
        this.[index].Cells[2].Value = "1111";
        this.[index].Cells[3].Value = "11111";
        this.[index].Cells[4].Value = "111111";
        this.[index].Cells[5].Value = "1111111";
        this.[index].Cells[6].Value = "*-*";

Several ways to add rows in datagridview

1. Data binding

 = true;
 = customersDataSet;

This will automatically generate rows of data for the corresponding data. If the column is not automatically generated, you need to manually add the column and set the column's data source property name (DataPropertyName) to the property name of the corresponding data class.

2. Add manually

    = 5;
   ....
   [0].Name = "Release Date";
   ....

string[] row0 = { "11/22/1968", "29", "Revolution 9", 
"Beatles", "The Beatles [White Album]" };
(row0);

In addition, the way to access row cells can be like this

this.[1].Cells[0].Value = "new value";
//Or, equivalentthis.dataGridView1[0, 1].Value = "new value";

The above is personal experience. I hope you can give you a reference and I hope you can support me more.