DataGridView应用
DataGridView应用:
应用1:将获取的行数据保存到实体
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { //获取行数据并转化为实体 Student student = dataGridView2.Rows[e.RowIndex].DataBoundItem as Student; MessageBox.Show(student.StuName + ":" + student.Sex + ":" + student.Phone); }
应用2:将获取的整个表格数据保存到实体集合
private void button1_Click(object sender, EventArgs e) { List<Student> list = new List<Student>(); list = dataGridView2.DataSource as List<Student>; }