c# DataGridViewCheckBoxColumn的问题,如何删除DataGridView里被选中的项?

2024-08-12 15:33:06
推荐回答(3个)
回答1:

foreach(DataGridViewRow row in this.dataGridView1.Rows){
if(row.Cells[1].Value!=null && Convert.ToBoolean(cell.Cells[1].Value)==true){
this.dataGridView1.Rows.Remove(row);
}
}
其中foreach循环遍历DataGridView每行,并查找单元格控件类型为丛迹DataGridViewCheckBoxColumn
的控件列的值,是true的,从渗拿并DataGridView中敏卜删除。

回答2:

for (int i = 0; i {
if (dataGridView1.Rows[i].Cells["Column1"].EditedFormattedValue.ToString() == "True")
{
this.dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
}
这样就OK了

回答3:

有两种方法:乎槐
1 调用DataGridView的属性,删除行。型派参考:
http://www.cnblogs.com/jxsoft/archive/2011/05/06/2038952.html
2 在复选框选择事件中直接删除DataGridView的数据源卜顷贺中的对应行,然后在重新绑定。