操作方法
新建一个Form做测试,包含一个DataGridView,DataGridView有三列,分别是学号,姓名,分数表示一个期末考试分数表。
双击添加数据按钮,填写添加数据代码: //some codeint index = this.dataGridView1.Rows.Add();this.dataGridView1.Rows[index].Cells[0].Value = textBox1.Text;this.dataGridView1.Rows[index].Cells[1].Value = textBox2.Text;this.dataGridView1.Rows[index].Cells[2].Value = textBox3.Text;
点击运行,填写数据
点击添加即可添加一行数据
方法二: 直接上代码: String[] values = {textBox1.Text,textBox2.Text,textBox3.Text };dataGridView1.Rows.Add(values);