How to add a row of data in a C# DataGridView?

To add a row of data to a DataGridView in C#, you can use the following code:

// 创建一个新的行对象
DataGridViewRow row = new DataGridViewRow();

// 创建单元格对象
DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell();
DataGridViewTextBoxCell cell2 = new DataGridViewTextBoxCell();
DataGridViewTextBoxCell cell3 = new DataGridViewTextBoxCell();

// 设置单元格的值
cell1.Value = "Value1";
cell2.Value = "Value2";
cell3.Value = "Value3";

// 将单元格添加到行中
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);

// 将行添加到DataGridView中
dataGridView.Rows.Add(row);

The code above creates a new row object, sets values for each cell, adds the cells to the row, and finally adds the row to the DataGridView.

Please make sure to replace dataGridView with the actual name of the DataGridView control you are using, and set the values of the cells as needed.

bannerAds