private void btnDelete_Click(object sender, EventArgs e) { int productId; //DialogResult strDelete = MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo); //if (strDelete.ToString().Equals("No")) //{ // return; //} if (dgvProduct.SelectedRows.Count > 0) { if (MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { try { if (dgvProduct.SelectedRows.Count > 0) { //productId = Convert.ToInt32(dgvProduct.CurrentRow.Cells["id"].Value.ToString()); productId = Convert.ToInt32((dgvProduct.SelectedRows[0].DataBoundItem as DataRowView).Row["id"].ToString()); if (pLogic.FrmPoeductDelete(productId)) { //MessageBox.Show("删除记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); SetDataGridView("", 0); } //else //{ // MessageBox.Show("删除记录失败,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); //} } } catch (Exception) { MessageBox.Show("记录正在使用,无法删除!"); } } } }