datagridview怎么把一行数据复制到另一个datagridview [C# VS2005]
这里是全部复制过去了,我想只复制一行,请问怎么改?DataTabletb1=(DataTable)this.dataGridView1.DataSource;DataTa...
这里是全部复制过去了,我想只复制一行,请问怎么改?
DataTable tb1 = (DataTable)this.dataGridView1.DataSource;
DataTable tb2 = new DataTable();
tb2 = tb1.Copy();
this.dataGridView2.DataSource = tb2; 展开
DataTable tb1 = (DataTable)this.dataGridView1.DataSource;
DataTable tb2 = new DataTable();
tb2 = tb1.Copy();
this.dataGridView2.DataSource = tb2; 展开
2个回答
展开全部
DataTable tb1 = (DataTable)this.dataGridView1.DataSource;
DataTable tb2 = new DataTable();
tb2 = tb1.Copy();
DataRow dr = tb2.NewRow();
dr[0]=dataGridView1.rows[n].Cells[0].value;
dr[1]=dataGridView1.rows[n].Cells[1].value;
dr[2]=dataGridView1.rows[n].Cells[2].value;
……n是你要复制行的索引
tb2.Rows.Add(dr);
this.dataGridView2.DataSource = tb2;
DataTable tb2 = new DataTable();
tb2 = tb1.Copy();
DataRow dr = tb2.NewRow();
dr[0]=dataGridView1.rows[n].Cells[0].value;
dr[1]=dataGridView1.rows[n].Cells[1].value;
dr[2]=dataGridView1.rows[n].Cells[2].value;
……n是你要复制行的索引
tb2.Rows.Add(dr);
this.dataGridView2.DataSource = tb2;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |