Why is my bound DataGridView throwing an “Operation not valid because it results in a reentrant call to the SetCurrentCellAddressCore function” error?

前端 未结 7 2223
旧时难觅i
旧时难觅i 2020-12-01 15:37

When binding a DataGridView control to a binding source, I\'m getting the following error in my application:

Operation is not valid becau

7条回答
  •  日久生厌
    2020-12-01 16:18

    This can be caused by manipulating the datasource while the DataGridview is in BeginEdit.

    Another solution is to SuspendBinding on the CurrencyManager of the DataGridView while manipulating the datasource.

    CurrencyManager currencyManager = (CurrencyManager)BindingContext[dataGridView1.DataSource];
    currencyManager.SuspendBinding();
    // Manipulate datasource
    currencyManager.ResumeBinding();
    

提交回复
热议问题