I have a question about DGV in windows Forms. So I have dgv1 where is written some information. Then I am filling second dgv2 with this code:
dataGridView2.DataSource = dataGridView1.DataSource;
and it works fine, but when I am changing something in dgv2 (removing row or column), it appears on dgv1 too. I can't understand why. I am just adding data from dgv1 into dgv2 and I want dgv1 to be so how it is (without changes). At the same time I want to change dgv2 and see the difference(between dgv1 and dgv2).
So who has idea why is it happening ?
I have solved it with this code:
dataGridView2.Columns.Add("Column1", "Name");
dataGridView2.Columns.Add("Column2", "Date");
dataGridView2.Columns.Add("Column3", "Time");
DataGridViewRow row = new DataGridViewRow();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
row = (DataGridViewRow)dataGridView1.Rows[i].Clone();
int intColIndex = 0;
foreach (DataGridViewCell cell in dataGridView1.Rows[i].Cells)
{
row.Cells[intColIndex].Value = cell.Value;
intColIndex++;
}
dataGridView2.Rows.Add(row);
}
dataGridView2.AllowUserToAddRows = false;
dataGridView2.Refresh();