如果将行添加到 DataTable
DataRow row = datatable1.NewRow();
row["column2"]="column2";
row["column6"]="column6";
datatable1.Rows.Add(row);
DataGridView
怎么样??
最佳答案
你可以这样做:
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/en-us/library/system.windows.forms.datagridview.rows.aspx
关于c# - 如何以编程方式向 datagridview 添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063770/