日期:2014-05-18 浏览次数:20931 次
if (dataGridView1.SelectedRows.Count > 0)
{
DialogResult result = MessageBox.Show("确定要删除选中项吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
for (int i = dataGridView1.SelectedRows.Count; i >= 1; i--)//从下往上删
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index);
}
if (radioButton1.Checked == true)
{
SqlCommandBuilder scb = new SqlCommandBuilder(sa);
sa.Update(ds.Tables["DATAWEI"]);
}
else if (radioButton2.Checked == true)
{
SqlCommandBuilder scb = new SqlCommandBuilder(sa);
sa.Update(ds.Tables["MAINDATAWEI"]);
}
else
{
SqlCommandBuilder scb = new SqlCommandBuilder(sa);
sa.Update(ds.Tables["OLDDATAWEI"]);
}
}
}
for (int i = dataGridView1.Rows.Count - 1; i >= 0; i--)
{
if (dataGridView1.Rows[i].Selected)
{
//删除
}
}
------解决方案--------------------
写在一个rowcommand 事件里面好像可以
------解决方案--------------------
for (int i = dataGridView1.SelectedRows.Count; i >= 1; i--)//从下往上删
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index);
}
你删了一个后,选中的数就少一个,,你这样写是不规范的