Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
WinGrid V17.1 exception InvalidOperationException: Operation can not be performed when not in edit mode.
posted

We've upgraded our WinForms project from 15.2 to 17.1.  

When editing (changing a cell value) and leaving the ultrawingrid the exception occurs, it's not being caught within the VS 2017 IDE as I've set it to break on this exception.  

The code is quite old, I think it's going wrong in this part of the code, as I've stepped through the code and set the activecell to nothing, which stops the exception occuring.

Dim ThisCell As UltraGridCell = Me.ActiveCell
If Not ThisCell Is Nothing Then
If ThisCell.IsInEditMode Then
Me.PerformAction(UltraGridAction.ExitEditMode, False, False)
If ThisCell.IsInEditMode Then
OutputTrace(ts.TraceWarning, "Cannot exit edit mode on leave, cell and row may not be updated or validated")
End If
End If
If IsDirty(ThisCell) Then
Dim ThisE As New CancelableCellEventArgs(ThisCell)
RaiseEvent ValidateCell(ThisGrid, ThisE)
If ThisE.Cancel Then Me.Focus()

ElseIf mValidationModeCell = IProgressDataEntryGrid.ValidationModeConstants.Always Then
Dim ThisE As New CancelableCellEventArgs(ThisCell)
RaiseEvent ValidateCell(ThisGrid, ThisE)
If ThisE.Cancel Then Me.Focus()

Else
'nothing to validate on cell
End If
End If

Has there been any changes in this area that would affect the operation, if so do you have any recommendations?

Many thanks

Keith

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Keith, 

    I looked into that error message and it occurs when the MaskedEditor is in the middle of an operation and tries to verify that it is still in edit mode. 

    You didn't say what event this code is called from. But my guess is that you are calling this in a Key or Mouse event and there's a masked editor in a grid cell that is trying to process that key or mouse operation and you are forcing the cell out of edit mode while it's in the middle of that process. 

    If that's the case, then a potential solution to that problem would be to institute some sort of delay instead of synchronously exiting edit mode in response to whatever event you are using. You can typically do that with a BeginInvoke. 

    Another possibility is that this is a threading issue. That seems unlikely since you seem to imply that the error is pretty consistent and threading issues tend to be inconsistent and only happen intermittently. Is your application using multiple threads? Are you creating a BackgroundWorker or other thread? 

    The reason you can't catch the exception is most likely because you have "Just My Code" debugging turned on in Visual Studio. So you probably just need to turn that off in order to catch the exception and see the call stack. To turn it off go to Tools-->Options-->Debugging and uncheck "Enable Just My Code."

Children