Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 326
priyanka Avatar asked Feb 25 '11 07:02

priyanka


2 Answers

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.

like image 180
Bradley Smith Avatar answered Oct 15 '22 22:10

Bradley Smith


This most likely caused by you attempting to refresh a DataGridView after a save. I suggest you invoke the method rather than just calling it.

   BeginInvoke(new MethodInvoker(PopulateControl ));
like image 32
CouncilScribe Avatar answered Oct 16 '22 00:10

CouncilScribe