c# - 如何以编程方式向 datagridview 添加新行

标签 c# winforms datagridview row

如果将行添加到 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/

相关文章:

winforms - TabPage 中的自动调整大小控件

c# - 如何在 Windows 窗体应用程序中保存应用程序设置?

c# - 控件移动后 Windows 窗体 MouseEnter 不触发

c# - 如何在datagridview中显示图片? C#

c# - 过滤数据绑定(bind)数据 GridView (带有组合框列)的数据 View 使其速度非常慢

c# - C# 代码中的 Excel 引用问题

c# - Toggleswitch 需要显式 "Mode=Twoway"

c# - 如何使用 Ssl Stream 获取/存储客户端证书?

c# - 已检查更改的 DataGridView 事件

c# - 如何在 WPF 中使用 OpenDialog 将文件复制到特定目录并设置文件名、扩展名?