您可以使用以下代码来实现C#中DataGridView选中多行数据删除的功能:
private void btnDelete_Click(object sender, EventArgs e){if (dataGridView1.SelectedRows.Count > 0){DialogResult result = MessageBox.Show("确定要删除选中的行吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);if (result == DialogResult.Yes){foreach (DataGridViewRow row in dataGridView1.SelectedRows){if (!row.IsNewRow){dataGridView1.Rows.Remove(row);}}}}else{MessageBox.Show("请先选择要删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);}}在上述代码中,btnDelete_Click是删除按钮的点击事件处理程序。首先,它会检查是否有选中的行,如果有则弹出对话框确认是否删除选中的行。如果用户确认删除,则遍历选中的行,并逐个删除它们。最后,如果没有选中的行,则显示一个提示消息。
请注意,这里使用了dataGridView1.SelectedRows属性来获取所有选中的行。然后,通过遍历每一行,使用dataGridView1.Rows.Remove方法来删除行。

