DataGridView插入一行数据和用DataTable绑定数据2种方式

以前不会用DataGridView的时候一直使用DataTable绑定的方式,如下:

DataTable table = new DataTable();
//给表添加一列Name,此名字和
table.Columns.Add("Name");
//给表添加一列Id
table.Columns.Add("Id");

DataRow row = table.NewRow();
row["Name"]="ab";
row[""Id]=1;
table.Rows.Add(row);

//当然,dataGridView1中的一列都需要绑定对应好
this.Column1.DataPropertyName = "Name";

this.dataGridView1.DataSource = table;

不过感觉使用起来比较麻烦,今天终于找到了另一种简单的方法:

this.dataGridView1.Rows.Add("ab",1)

即可。

  

原文地址:https://www.cnblogs.com/wishFreedom/p/3386056.html