[英]add new row to datagridview programmatically
我尝试向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?
这些代码可以帮助您:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.