dataGridView1.Rows[0].Cells[0].Value = textBox1.Text.ToString();
                        dataGridView1.Rows[0].Cells[1].Value = textBox3.Text.ToString();
                        dataGridView1.Rows[0].Cells[2].Value = textBox5.Text.ToString();
                        dataGridView1.Rows[0].Cells[3].Value = textBox6.Text.ToString();
                        string[] row = new string[]
                        {
                            dataGridView1.Rows[0].Cells[0].Value.ToString(),
                            dataGridView1.Rows[0].Cells[1].Value.ToString(),
                            dataGridView1.Rows[0].Cells[2].Value.ToString(),
                            dataGridView1.Rows[0].Cells[3].Value.ToString(),
                        };     
                        dataGridView1.Rows.Add(row);
这是代码运行后,产生结果,新输入数据会显示两行,再次输入两行变一行,新输入者还是两行,不知道问题在那边,跪求真因

解决方案 »

  1.   

    dataGridView1.Rows.Add(row);这又增加了一行,肯定是两行了
      

  2.   

    就是这里的问题。每次都是dataGridView1.Rows[0],而且后面还有
    dataGridView1.Rows.Add(row);
      

  3.   

    把你的代码改一下:            int index=dataGridView1.Rows.Add();
                dataGridView1.Rows[index].Cells[0].Value = textBox1.Text.ToString();
                dataGridView1.Rows[index].Cells[1].Value = textBox2.Text.ToString();
                dataGridView1.Rows[index].Cells[2].Value = textBox3.Text.ToString();
                dataGridView1.Rows[index].Cells[3].Value = textBox4.Text.ToString();