SaraniO SaraniO - 1 month ago 12
C# Question

How to avoid reentrant call to the SetCurrentCellAddressCore function in datagridview end edit event in C#

I have a

datagridview
with
datasource
of a
datatable
,
when the user change the value of it(in cell of
datagridview
),
cellendedit
update the data to
database
and after that new data from
database
set to that datatable and load in
datagridview
.

when I end edit of cell by pressing enter button everything is Ok, but when I want to end edit by leaving the focus from cell this exception occurred:


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


with this code I make the error goes away:

private void RationFormulationdgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (!RationFormulationdgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
{
return;
}

RationFormulationDBConnection.UpdateFeedsDetails(this);
RationFormulationDBConnection.SetFeedsIntoRationdormulationdgv(this);
}


But the problem is edit is not applied when losing focus.

how should I fix this?

Answer

I solve my problem by moving coeds from CellEndEdit event to Cellvaluechanged event and it seems ok and coeds runs without any problem