现在两个datagridview控件gridview1和gridview2,gridview1中有数据行,gridview2中无数据行,代码如下:
for (int i = 0; i < gridview1.Rows.Count; i++)
{
gridview2.Rows.Add();//在gridview2中添加一空行
//为空行添加列值
for (int j = 0; j < gridview1.Rows[i].Cells.Count; j++)
{
gridview2.Rows[i].Cells[j].Value = gridview1.Rows[i].Cells[j].Value;
}
}
说明:外层循环为gridview2添加一个空行,内层循环为新添加的空行的每列赋值。