Exemplo n.º 1
0
 private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult dr = MessageBox.Show("是否要删除?", "提示", MessageBoxButtons.YesNo);
         if (dr == DialogResult.Yes)
         {
             List <int> idtrr = new List <int>();
             for (int i = this.dataGridView1.SelectedRows.Count; i > 0; i--)
             {
                 if (dataGridView1.SelectedRows[i - 1].Cells[0].Value == null || dataGridView1.SelectedRows[i - 1].Cells[0].Value is DBNull)
                 {
                     DataRowView drv = dataGridView1.SelectedRows[i - 1].DataBoundItem as DataRowView;
                     if (drv != null)
                     {
                         drv.Delete();
                         i = i - 1;
                     }
                     i = i - 1;
                 }
                 else
                 {
                     idtrr.Add(Convert.ToInt32(dataGridView1.SelectedRows[i - 1].Cells[0].Value));
                 }
             }
             cal.deleteSehao(idtrr);
             this.backgroundWorker1.RunWorkerAsync();
             JingDu form = new JingDu(this.backgroundWorker1, "删除中");// 显示进度条窗体
             form.ShowDialog(this);
             form.Close();
             MessageBox.Show("删除成功!");
             bindDatagridView();
         }
     }
     catch (Exception ex)
     {
         //throw ex;
         MessageBox.Show(ex.Message);
     }
 }