以编程方式向datagridview添加新行 [英] add new row to datagridview programmatically

查看:45
本文介绍了以编程方式向datagridview添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向datagridview添加新行,我尝试使用此代码

I try to add new row to datagridview ,I try by using this code

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);

它没有用,所以我尝试了

it didn't work so i try this

dgv_OfferTerms.Rows.Add(cond.Id,cond.Name,cond.Title,cond.Description);

不起作用如何将新行添加到datagridview?

didn't work how can i add new row to datagridview??

推荐答案

这些代码可以为您提供帮助:

These code may help you:

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/zh-cn/library/system.windows.forms.datagridview.rows.aspx

这篇关于以编程方式向datagridview添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆