如何添加一个新行以编程的DataGridView [英] How to add a new row to datagridview programmatically

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

问题描述

如果添加行数据表

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

从:<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx

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

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