日期:2014-05-17  浏览次数:20796 次

dataGridView不绑定数据库,增加行怎么会把前面的数据清除掉的,奇怪
开发windows form程序时,dataGridView不绑定数据库,我点击这个按钮几次,数据只能在最后面的那条上有,前面增加的数据自动清除掉了,如果我手动修改这些内容,则不会自动消失了,奇怪  
  private void button3_Click(object sender, EventArgs e)
  {
  this.dataGridView1.Rows.Add();
  this.dataGridView1.Rows[1].Cells[1].Value = "1111,111";
  this.dataGridView1.Rows[this.dataGridView1.NewRowIndex].Cells[2].Value = "2222222222";
  this.dataGridView1.Rows[this.dataGridView1.NewRowIndex].Cells[3].Value = "wwwwwwwwwww";
  }


------解决方案--------------------
数据只能在最后面的那条上有 你这什么意思啊

打断点仔细调试一下两者的区别
------解决方案--------------------
Rows[1],这个一直在这行上写,还有你的 NewRowIndex 变化了吗,如果没变,肯定是同一行
------解决方案--------------------
//这样获取新追加行的index 
int index = this.dataGridView1.Rows.Add();
 this.dataGridView1.Rows[index].Cells[0].Value = "1111,111";
 this.dataGridView1.Rows[index].Cells[1].Value = "2222222222";