我需要根据windows窗体的datagridview中的某些条件删除一个单元格。
下面是我的代码。
private void grdvTest_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
try
{
var grdv = sender as DataGridView;
foreach (DataGridViewRow row in grdv.Rows)
{
DataGridViewCell BookButtonCell = row.Cells[0];
ViewModelMyItem item = row.DataBoundItem as ViewModelMyItem;
if (item.IsDeleted)
{
row.Cells.Remove(BookButtonCell);
}
}
}
catch (Exception ex)
{
throw ex
}
}
错误:
row.Cells.Remove(BookButtonCell);
Collection已属于DataGridView控件。此操作不再有效。