با سلام خدمت دوستان و اساتید
من یک تابع برای اینکه یک کلون از یک دیتا گرید ویو بده نوشتم دوستان لطف کنن استفاده کنن و اشکالاتشو بگن تا برطرف کنم

public static DataGridView CloneDataGridView(DataGridView dgv)
{
try
{
DataGridView ResultDGV = new DataGridView();
ResultDGV.ColumnHeadersDefaultCellStyle = dgv.ColumnHeadersDefaultCellStyle.Clone();
DataGridViewCellStyle dtgvdcs = dgv.RowsDefaultCellStyle.Clone();
dtgvdcs.BackColor = dgv.DefaultCellStyle.BackColor;
dtgvdcs.ForeColor = dgv.DefaultCellStyle.ForeColor;
dtgvdcs.Font = dgv.DefaultCellStyle.Font;
ResultDGV.RowsDefaultCellStyle = dtgvdcs;
ResultDGV.AlternatingRowsDefaultCellStyle = dgv.AlternatingRowsDefaultCellStyle.Clone();
for (int i = 0; i < dgv.Columns.Count; i++)
{
DataGridViewColumn DTGVC = dgv.Columns[i].Clone() as DataGridViewColumn;
DTGVC.DisplayIndex = dgv.Columns[i].DisplayIndex;
if (DTGVC.CellType == null)
{
DTGVC.CellTemplate = new DataGridViewTextBoxCell();
ResultDGV.Columns.Add(DTGVC);
}
else
{
ResultDGV.Columns.Add(DTGVC);
}
}
foreach (DataGridViewRow var in dgv.Rows)
{
DataGridViewRow Dtgvr = var.Clone() as DataGridViewRow;
Dtgvr.DefaultCellStyle = var.DefaultCellStyle.Clone();
for (int i = 0; i < var.Cells.Count; i++)
{
Dtgvr.Cells[i].Value = var.Cells[i].Value;
}
if (var.Index % 2 == 0)
Dtgvr.DefaultCellStyle.BackColor = ResultDGV.RowsDefaultCellStyle.BackColor;
ResultDGV.Rows.Add(Dtgvr);
}
return ResultDGV;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return null;
}


در ضمن لینک دوباره راه افتاده میتونین دانلود کنین و هیچ مشکلی نداره