Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
datagride with 3 column column 0 and 2 is editable ....when user type value in column 0 and press enter its goes to column 2 and this column is in edit mode ...

error generate
"System.InvalidOperationException: 'Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.


What I have tried:

VB
Private Sub DgvData_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvData.CellEndEdi

Dim iColumn = DgvData.CurrentCell.ColumnIndex
Dim iRow = DgvData.CurrentCell.RowIndex

If DgvData.Columns.Count = 3 Then
If iColumn = DgvData.ColumnCount - 1 Then
If iRow < DgvData.RowCount - 1 Then
DgvData.CurrentCell = DgvData(0, iRow + 1)
DgvData.BeginEdit(True)
                End If
            Else
                If iRow < DgvData.RowCount - 1 Then
                    SendKeys.Send("{Up}")
                End If
If DgvData.Rows(iRow).Cells(0).Value.ToString = "" And DgvData.RowCount - 1 = 0 Then
                    DgvData.CurrentCell = DgvData(0, 0)
                    DgvData.BeginEdit(True)

Else
                    DgvData.CurrentCell = DgvData(iColumn + 2, iRow)
                    DgvData.BeginEdit(True)
End if
End if
End if
Posted
Updated 27-Jun-20 21:44pm
v3
Comments
Richard MacCutchan 17-May-20 3:59am    
You are trying to edit the data inside your edit handler. You are not allowed to do that as it will cause the handler to be called again from inside the handler, which will cause the handler to be called ...
KM999 17-May-20 4:43am    
can you provide EndEdit handler code
Richard MacCutchan 17-May-20 7:46am    
No you need to redesign your handler so that it does not try to start an edit process.

1 solution

The word you are looking for is "recursion" and it's not allowed in this context.
You can't use "BeginEdit" for the same DGV inside it's EndEdit handler (or any other eidt based handler): that could cause a recursive editing loop that would blow your stack and crash your app.

It's like taking money from an ATM: that causes your bank account total to be reduced. But if there was a "reduced bank account" handler that added a fee for each reduction, the withdrawal would trigger it - and that would add a fee, which would trigger it again, and again, and again, ... until the fees emptied your account, and the bank decided you couldn't have the cash from the ATM to start with.

Think about what you are actually trying to achieve - this is not the right approach!
 
Share this answer
 
Comments
KM999 17-May-20 4:58am    
can you please update my code....thanks in advance
OriginalGriff 17-May-20 5:32am    
No, I can't - I have no idea what you expect that code to do, or what task you are trying to achieve. I also don't have any access to the rest of your code to get any idea how it works!

As I said in my original answer "Think about what you are actually trying to achieve - this is not the right approach!"
KM999 17-May-20 5:44am    
datagride with 3 column column 0 is editable and 2 is editable ....when user type value in column 0 and press enter its goes to column 2 and this column is in edit mode ...
when column 0 is blank and user hit enter its save data...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900