private void button3_Click(object sender, EventArgs e) { int k = dataGridView1.SelectedRows.Count; if (MessageBox.Show("您确认要删除这" + Convert.ToString(k) + "项吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)//给出提示 { } else { if (k != dataGridView1.Rows.Count - 2)//因为还有一行为统计行所以减2 { for (int i = k; i >= 1; i--)//从下往上删,避免沙漏效应 { dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i - 1].Index); } } else { dataGridView1.Rows.Clear(); } }