日期:2014-05-18  浏览次数:20797 次

datagridview不用数据源,而是直接一行一行的添加行如何做?
想做成流水信息,即发现有数据,就将该信息加入datagridview中显示。所以不能使用数据源dataset。而是动态生成一行。
以下代码不通过:提示错误:索引超出范围。必须为非负值并小于集合大小

以下为增加一行
  DataGridViewRow row = new DataGridViewRow();
  row.Cells[0].Value = "1";
  row.Cells[1].Value = "2";
  this.dataGridView1.Rows.Add(row);
 

------解决方案--------------------
this.dataGridView1.Rows.Add();
this.datagridView1.Rows[this.dataGridView1.NewRowIndex].cell[0].Value = "";