private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e) { if (dataGridView1.CurrentRow == null) { return; } if (MessageBox.Show("是否要删除这条数据?", "请选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int user_id = int.Parse(dataGridView1.CurrentRow.Cells["userId"].Value.ToString()); if (user_id == 2) { MessageBox.Show("默认用户禁止删除!"); return; } if (db.DeleteUser(user_id) != 0) { dataGridView1.Rows.Remove(dataGridView1.CurrentRow); return; } MessageBox.Show("删除失败!"); } }