小编典典

如何以编程方式向datagridview添加新行

c#

如果将行添加到 DataTable

DataRow row = datatable1.NewRow();
row["column2"]="column2";
row["column6"]="column6";
datatable1.Rows.Add(row);

怎么样DataGridView??


阅读 266

收藏
2020-05-19

共1个答案

小编典典

你可以做:

DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells[0].Value = "XYZ";
row.Cells[1].Value = 50.2;
yourDataGridView.Rows.Add(row);

要么:

DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells["Column2"].Value = "XYZ";
row.Cells["Column6"].Value = 50.2;
yourDataGridView.Rows.Add(row);

另一种方式:

this.dataGridView1.Rows.Add("five", "six", "seven","eight");
this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");

来自:http :
//msdn.microsoft.com/zh-
cn/library/system.windows.forms.datagridview.rows.aspx

2020-05-19