我在 SO 上看到了关于这个主题的一些问题,但建议的修复在我的代码中没有任何变化。
这就是我所拥有的。
public void cell_formatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
//lots of work
if (dataGridView.Columns[e.ColumnIndex].Name.Equals("Helped"))
{
if (e.Value.Equals(true))
{
CurrencyManager cm = (CurrencyManager)dataGridView.BindingContext[dataGridView.DataSource];
cm.SuspendBinding();
dataGridView.Rows[e.RowIndex].Visible = false; //Error here
cm.ResumeBinding();
}
附加信息:与货币经理职位相关的行不能隐藏。
以上几乎是对大多数其他用户的修复,任何猜测为什么它不适合我?
编辑:
我添加了一个新行来清除 CurrentCell,它现在提供了一个新错误;
if (dataGridView.Columns[e.ColumnIndex].Name.Equals("Helped"))
{
if (e.Value.Equals(true))
{
CurrencyManager cm = (CurrencyManager)dataGridView.BindingContext[dataGridView.DataSource];
cm.SuspendBinding();
dataGridView.CurrentCell = null;
dataGridView.Rows[e.RowIndex].Visible = false;
cm.ResumeBinding();
}
}
操作无效,因为它会导致对 SetCurrentCellAddressCore 函数的可重入调用。