将datagridview的ROW数据复制到另一个

时间:2013-08-16 09:49:24

标签: c# asp.net visual-studio-2010 datagridview indexing

我需要将datagridview(grid_display)中的SINGLE行复制到另一个datagridview(grid_detail)

我可以复制列标题。如下所示。

foreach (DataGridViewColumn c in grid_display.Columns)
{
    grid_detail.Columns.Add(c.Clone() as DataGridViewColumn);

}

//then you can copy the rows values one by one (working on the selectedrows collection)
foreach (DataGridViewRow r in grid_display.SelectedRows)
{
    int index = grid_detail.Rows.Add(r.Clone() as DataGridViewRow);
    foreach (DataGridViewCell o in r.Cells)
    {
        grid_detail.Rows[index].Cells[o.ColumnIndex].Value = o.Value;
    }
}

如何将grid_display中的SINGLE选定行的DATA复制到grid_detail?

0 个答案:

没有答案