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

priyanka picture priyanka · Feb 25, 2011 · Viewed 33.7k times · Source

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

Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function

The binding source depends on the data table. And I'm filtering the records from the DataGridView. And I used the dataGridView1_CellValueChanged() event where I'm filtering the DataGridView. But when I was deleting the data from the current cell, this error occurs.

How can I resolve this problem?

Answer

Bradley Smith picture Bradley Smith · Feb 25, 2011

The exception is raised by the DataGridView in order to prevent an infinite loop from occurring. The cause of this is usually one of the following:

  • Changing the active cell while an operation is being performed on the currently-active cell
  • Beginning, ending or cancelling edit mode while a cell edit is already in-progress
  • Any other operation that results in the active cell being changed while the DataGridView is still using it

Have a look at your handler for the CellValueChanged event and make sure you are not doing any of the above within the handler.