Thursday, October 29, 2015

Fix WinForms DataGridView Exception: 'Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.'

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

The exception may occur while calling a refresh function on DataGridView after doing a cell edit and click another cell. 

To fix this add the below line in the CellEndEdit event method of the DataGridView.

 this.BeginInvoke(new MethodInvoker(Refresh_MyDataGridView_Method)); 


Example:

 private void MyDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) 
 {
 ... 
 ...
 ...
 this.BeginInvoke(new MethodInvoker(Refresh_MyDataGridView_Method)); 
 }


--

No comments: