日期:2014-05-17 浏览次数:20891 次
dataGridView2.Columns.Clear(); //复制前先清空
for (int i = 0; i < dataGridView1.Columns.Count; i++) //添加列 奇怪,明明添加的是dgv1列的Clone,却还要用as转换?
dataGridView2.Columns.Add(dataGridView1.Columns[i].Clone() as DataGridViewColumn);
for (int i = 0; i < dataGridView1.Rows.Count; i++) //添加行
dataGridView2.Rows.Add(dataGridView2.Rows[i].Clone());
//获取单元格的值
for (int rowscount = 0; rowscount < dataGridView1.Rows.Count; rowscount++)
{
for (int cellscount = 0; cellscount < dataGridView1.Rows[rowscount].Cells.Count; cellscount++)
dataGridView2.Rows[rowscount].Cells[cellscount].Value = dataGridView1.Rows[rowscount].Cells[cellscount].Value;
}