向DataTable添加新行 [英] Add a new row to a DataTable

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

问题描述

csvData是绑定到DataGridView的DataTable。编译并运行没有错误。 。但刷新后,网格中不会出现新行。 。 。 ??是否缺少某些东西?





private void addNewRowButton_Click(object sender,EventArgs e)

{

csvData.NewRow();

DataGridView1.Refresh();



}



addNewRowButton的发件人是Form1。 。 。一个WINDOWS表单。

csvData is a DataTable bound to a DataGridView. Compiles & runs no errors . . but after refresh, no new row appears in grid . . . ?? Is there something missing?


private void addNewRowButton_Click(object sender, EventArgs e)
{
csvData.NewRow();
DataGridView1.Refresh();

}

The sender of the addNewRowButton is the Form1 . . . a WINDOWS form.

推荐答案

也许你可以帮忙将新行添加到表中吗?

DataTable.NewRow [ ^ ]只是创建一个新的具有正确架构/列的空白行...
Perhaps it would help is you added the new row to the table?
DataTable.NewRow[^] just creates a new blank row with the correct schema / columns...


您需要再次绑定DGV,如下所示。

You need to bind the DGV again like below.
private void addNewRowButton_Click(object sender, EventArgs e)
{
    csvData.NewRow();
    // Provide Column values for the New Row.

    DataGridView1.DataSource = csvData;
    DataGridView1.DataBind();
}


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

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