110,538
社区成员
发帖
与我相关
我的任务
分享
this.dataGridViewX1.Rows.Add(txtCode.Text.Trim(), txtName.Text.Trim());
DataTable table = new DataTable();
table.Columns.Add("id");
table.Columns.Add("name");
DataRow row = table.NewRow();
row["id"] = "007";
row["name"] = "hello world";
table.Rows.Add(row);
dataGridView1.DataSource = table;
//下面在给他新添加一行数据
DataRow addRow = table.NewRow ();
addRow["id"] = "008";//对应1列添加
addRow["name"] = "nihaoma";//对应列2添加
table.Rows.Add(addRow );//把新列放在table中去
this.dataGridView1.DataSource = table;//在绑定一次