C# datagridview 问题
请问
Form1
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.ShowDialog();
cla = f1.CLA;
dcop();
}
private void dcop()
{
for (int i = 0; i < cla.Count; i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = cla[i].商品类型;
dataGridView1.Rows[i].Cells[1].Value = cla[i].商品编码;
dataGridView1.Rows[i].Cells[2].Value = cla[i].商品名称;
dataGridView1.Rows[i].Cells[3].Value = cla[i].规格型号;
dataGridView1.Rows[i].Cells[4].Value = cla[i].单位;
dataGridView1.Rows[i].Cells[5].Value = cla[i].价格;
dataGridView1.Rows[i].Cells[6].Value = cla[i].数量;
dataGridView1.Rows[i].Cells[7].Value = cla[i].价格;
}
}
Form2
public List<DallClass1> CLA { get { return cla; } set { cla = value; } }
private void button1_Click(object sender, EventArgs e)
{
cla = new List<DallClass1>();
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if ((bool)dataGridView2.Rows[i].Cells[0].EditedFormattedValue == true)
{
DallClass1 dc = new DallClass1();
dc.商品类型 = dataGridView2.Rows[i].Cells[2].Value.ToString();
dc.商品编码 = dataGridView2.Rows[i].Cells[3].Value.ToString();
dc.商品名称 = dataGridView2.Rows[i].Cells[4].Value.ToString();
dc.规格型号 = dataGridView2.Rows[i].Cells[5].Value.ToString();
dc.单位 = dataGridView2.Rows[i].Cells[6].Value.ToString();
dc.价格 = dataGridView2.Rows[i].Cells[7].Value.ToString();
CLA.Add(dc);
}
}
this.Close();
}
为什么Form1第二次接收Form2传的值会把Form2第一次传的值给覆盖了