dataGridView动态添加行,新行排名第一行
DataGridViewRow row = new DataGridViewRow();
DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
textboxcell.Value = C.time;
row.Cells.Add(textboxcell);
DataGridViewTextBoxCell textboxcel2= new DataGridViewTextBoxCell();
textboxcell.Value = C.temperature;
row.Cells.Add(textboxcel2);
dataGridView1.Rows.Insert(1, row);//这句代码保存提供的行索引超出范围。
参数名: rowIndex
------解决方案--------------------dataGridView1.Rows.Insert(0, row);
------解决方案--------------------//要加这两句,添加列
this.dataGridView1.Columns.Add("1", "1");//两个参数,前者为列名,后者为headertext
this.dataGridView1.Columns.Add("2", "2");
DataGridViewRow row = new DataGridViewRow();
DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
textboxcell.Value = 1;
row.Cells.Add(textboxcell);
DataGridViewTextBoxCell textboxcel2 = new DataGridViewTextBoxCell();
textboxcel
2.Value = 2;//这里是2,是1的话,就覆盖了
row.Cells.Add(textboxcel2);
dataGridView1.Rows.Insert(0, row);//这里是0,索引从0开始。