使用添加按钮C#将列从数据网格复制到另一个网格 [英] copy columns from a datagrid to another using add button C#
本文介绍了使用添加按钮C#将列从数据网格复制到另一个网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好...我想找到一种方法,可以通过使用按钮将某些特定的列从数据网格复制到另一列(以相同的形式)...有什么想法吗?
我正在使用Visual Studio 2010
hello everybody... i want to find a way to copy some specific columns from a datagrid to another (in the same form) by using a button... any ideas??
i am using visual studio 2010
推荐答案
以下代码会将每一行从一个网格复制到另一网格.
The following code will copy each row from one grid to another.
foreach (DataRow row in dataTable1.Rows)
{
dataTable2.Rows.Add(row.ItemArray);
}
如果要复制某些特定的列,请在复制到另一个网格时使用if语句.变成:
If you want to copy some specific columns use a if statment while copying to the other grid. So it becomes:
foreach (DataRow row in dataTable1.Rows)
{
if(Condition)
{
dataTable2.Rows.Add(row.ItemArray);
}
}
祝你好运,
OI
Good luck,
OI
这篇关于使用添加按钮C#将列从数据网格复制到另一个网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文