【发布时间】:2012-03-08 14:16:09
【问题描述】:
我有一个显示来自 XML 文件的数据的 datagridview。 DGV 称为任务表。 我在每一行都有一个复选框和一个按钮,该按钮应该删除任何选中了复选框的行。
但是,如果同时从 DGV 和后端 XML 文件中选择多行,我需要删除多行时,我一次只能删除一行。
这是一次成功删除一行的代码:
private void RemoveButton_Click_1(object sender, EventArgs e) // removes checked tasks.
{
int i = 0;
{
for (i = 0; i <= TaskTable.Rows.Count - 1; i++)
{
if (TaskTable.Rows[i].Cells[0].Value != null)
{
if ((bool)TaskTable.Rows[i].Cells[0].Value == true)
{
if (MessageBox.Show("Are you sure you want to remove the selected task?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) // confirmation
{
TaskTable.Rows.RemoveAt(i); //Here If Checkbox Selected Then It Will Delete The Row From The GridView
}
}
}
}
}
TaskDataSet.WriteXml(fileURL);
TaskDataSet.AcceptChanges(); // re writes xml file and removes deleted tasks.
}
请帮我修改我的代码,让我一次删除多个任务。
【问题讨论】:
标签: c# xml winforms datagridview checkbox