//班级表的单元格单击事件 private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e) { //选中行的图书编号 int str = -1; try { str = (int)dataGridView4.Rows[e.RowIndex].Cells[0].Value; } catch (Exception) { } //DataGridView的总列数 int rows = dataGridView4.Columns.Count; if (e.ColumnIndex == rows - 2)//修改 { Class c = new Class(); c.ClassId = str; c.ClassName = dataGridView4.Rows[e.RowIndex].Cells[1].Value.ToString(); Edit_UI exit = new Edit_UI(); exit.aa = this; exit.c = c; exit.Text = "修改班级"; exit.ShowDialog(); } else if (e.ColumnIndex == rows - 1)//删除 { DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { if (class_bll.deleteClass(str) > 0) { this.dataGridView4.DataSource = class_bll.selectClass1().Tables[0]; } else { MessageBox.Show("删除失败!"); } } } }
//用户类型表的单元格单击事件 private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { //选中行的图书编号 int str = -1; try { str = (int)dataGridView2.Rows[e.RowIndex].Cells[0].Value; } catch (Exception) { } //DataGridView的总列数 int rows = dataGridView2.Columns.Count; if (e.ColumnIndex == rows - 2)//修改 { UserType r = new UserType(); r.UserTypeId = str; r.UserTypeName = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); Edit_UI exit = new Edit_UI(); exit.aa = this; exit.r = r; exit.Text = "修改用户类型"; exit.ShowDialog(); } else if (e.ColumnIndex == rows - 1)//删除 { DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { if (readerType_bll.deleteUser(str) > 0) { this.dataGridView2.DataSource = readerType_bll.selectUserType1().Tables[0]; } else { MessageBox.Show("删除失败!"); } } } }