我有一个DataGridView和一个Button.如果选择了行,我想通过单击按钮删除它们.我尝试了类似的命令RemoveAt,SelectedRows等等,但没有做的工作.我怎么解决这个问题?
我尝试过类似的东西:
if (dataGridView2.SelectedRows.Count > 0)
{
DataGridViewSelectedRowCollection rows = dataGridView2.SelectedRows;
dataGridView2.Rows.RemoveAt(rows);
}
Run Code Online (Sandbox Code Playgroud)
但RemoveAt方法只接受整数.在我使用Selected Cells尝试它之前,他删除了所有行,因为总是选择一个单元格.