我尝试向datagridview添加新行,我尝试使用此代码
DataGridViewRow row = (DataGridViewRow)dgv_OfferTerms.Rows[0].Clone();
row.Cells[0].Value = cond.Id;
row.Cells[1].Value = cond.Name;
row.Cells[2].Value = cond.Title;
row.Cells[3].Value = cond.Description;
dgv_OfferTerms.Rows.Add(row);
它没有用,所以我试试这个
dgv_OfferTerms.Rows.Add(cond.Id,cond.Name,cond.Title,cond.Description);
没用 如何向datagridview添加新行?
答案 0 :(得分:2)
这些代码可以帮助您:
this.dataGridView1.Rows.Add("five", "six", "seven","eight");
this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");
或:
DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
row.Cells["Column2"].Value = "XYZ";
row.Cells["Column6"].Value = 50.2;
yourDataGridView.Rows.Add(row);
参考文献:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx