Example #1
0
 /// <summary>
 /// 单击单元格内容时发生
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == dataGridView1.Columns["cDel"].Index)
     {
         if (MessageBox.Show(this, "确定要删除吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             object v = dataGridView1.Rows[e.RowIndex].Cells["cName"].Value;
             if (v != null)
             {
                 Agent no = new Agent();
                 if (no.IsRelation(v.ToString()))
                 {
                     MessageBox.Show("该记录已被使用,禁止删除!");
                     return;
                 }
                 bool re = no.Delete(v.ToString());
                 if (re)
                 {
                     MessageBox.Show("删除成功!");
                     BindDGV("");
                 }
                 else
                 {
                     MessageBox.Show("删除失败!");
                 }
             }
         }
     }
     else if (e.ColumnIndex == dataGridView1.Columns["cModity"].Index)
     {
         object v = dataGridView1.Rows[e.RowIndex].Cells["cName"].Value;
         if (v != null)
         {
             frmCustomerUpdate f = new frmCustomerUpdate(v.ToString());  // 本项目的 frmCustomerUpdate 窗体
             f.ShowDialog();
             if (f._isOK)
             {
                 BindDGV("");
             }
         }
     }
 }