private void btnDelete_Click(object sender, EventArgs e)
{
if (!IsCheck())
{
MessageBox.Show("请选择要删除的数据");
}
else
{
DialogResult dt = MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.OKCancel);
//删除表中的数据
if (dt == DialogResult.OK)
{
PreStock psk = new PreStock();
//批量删除
string Ids = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null) //判断该行的复选框是否存在
{
if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "True") //判断该复选框是否被选中
{
Ids += dataGridView1.Rows[i].Cells["Id"].Value.ToString() + ",";
}
}
}
Ids = Ids.Substring(0, Ids.Length - 1);
bool res = (psk.DeleteList(Ids));
if (res==true){
MessageBox.Show("删除成功");
}
bindList();
}
}
}
private bool IsCheck()
{
bool ischecked = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null) //判断该行的复选框是否存在
{
ischecked = true;
break;
}
}
return ischecked;
}
winform 实现批量删除
最新推荐文章于 2018-10-15 16:05:55 发布