1

我需要将一个数据网格视图(grid_display)中的单行复制到另一个数据网格视图(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 复制到 grid_detail ?

4

0 回答 0