//以下步骤可以通过在dataGridView1上直接添加列自动生成
DataGridViewTextBoxColumn column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
column1.DataPropertyName = “Sex”;//这里的Sex和Student类中的属性名一致
column1.HeaderText = “性别”;
column1.Name = “column1”;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {column1});
Student[] list = new Student[2];//换成List<Student>也是一样的
list[0] = new Student("zhangsan", "girl");
list[1] = new Student("lisi", "boy");
this.dataGridView1.DataSource = list;
直接添加数据
int index = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[index].Cells[0].Value = “1”;
this.dataGridView1.Rows[index].Cells[1].Value = “11”;
this.dataGridView1.Rows[index].Cells[2].Value = “1111”;
this.dataGridView1.Rows[index].Cells[3].Value = “11111”;
this.dataGridView1.Rows[index].Cells[4].Value = “111111”;
this.dataGridView1.Rows[index].Cells[5].Value = “1111111”;
this.dataGridView1.Rows[index].Cells[6].Value = “-”;