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
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."
Hi, I also upgraded to 17.1 (from 16.1) and am experiencing the same behavior. I cannot figure out where the error is occurring because it is being caught in my unhandled error routine. Here is the exact error:
StellarSystemsPM.exe Error: 0 : [HeaterMain]: [HeaterMain]: System.InvalidOperationException: Operation can not be performed when not in edit mode. at Infragistics.Win.EditorWithMask.EnsureInEditMode() at Infragistics.Win.EditorWithMask.get_Sections() at Infragistics.Win.EditorWithMask.OnControlLeave(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Control.OnLeave(EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.OnLeave(EventArgs e) at System.Windows.Forms.Control.NotifyLeave() at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
I also attached a screenshot of my Debug options scre
I would appreciate any guidance...thanks!
Steve
Hi Steve,
It's hard to be sure, but from call stack, it appears that you are using the UltraControlContainerEditor to embed an UltraMaskEditor control in the grid. There's nothing neccessarily wrong with that, but it's kind've a roundabout way of doing it. The grid already has built-in support for masks. And even if it didn't, it has built-in support for editors so you could just use a Masked editor, instead of an UltraMaskedEditControl and a ControlContainerEditor. I don't know if that has anything to do with the exception you are getting, but I suspect it might.
Anyway, without being able to reproduce the issue, there's not much more I can tell you beyond what I've already explained. Somehow, you must have a cell in edit mode with an embedded UltraMaskedEditor control in it (using the UltraControlContainer). And the grid is losing focus for some reason - presumably the user clicked outside the grid. And then while the focus is being pulled away from the MaskedEditor control, something is trying to access the Sections property, which cannot happen while the control is not in edit mode.
My advice would be to figure out why you are jumping through hoops using the UltraControlContainerEditor and the UltraMaskedEditor control here instead of just applying a mask to the cell. There may be a good reason for that, and even if there isn't it should work, but maybe you don't need to do that and can get around the issue by taking a simpler approach.
If that doesn't help, maybe you can try to narrow the issue down to a small sample project you can post here and I can check it out.
Hi Mike,
I have had the same exception:
System.InvalidOperationException: Operation can not be performed when not in edit mode. at Infragistics.Win.EditorWithMask.EnsureInEditMode() at Infragistics.Win.EditorWithMask.get_Sections() at Infragistics.Win.EditorWithMask.OnControlLeave(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Control.OnLeave(EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.OnLeave(EventArgs e) at System.Windows.Forms.Control.NotifyLeave() at System.Windows.Forms.ContainerControl.UpdateFocusedControl() at System.Windows.Forms.ContainerControl.AssignActiveControlInternal(Control value) at System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control, Boolean originator) at System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control, Boolean originator) at System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control, Boolean originator) at System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control) at System.Windows.Forms.Control.WmSetFocus(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Now I have commented out the "PerformAction( UltraGridAction.ExitEditMode )" in the Leave event and this does prevent the exception in my case.In the versions before V17.1, it didn't throw an exception.
public void Grid_Leave( object sender, EventArgs e ){ //if( Grid != null ) // Grid.PerformAction( UltraGridAction.ExitEditMode ); // not anymore calling for WinGrid V17.1, // in older versions it did not produce an exception }Your explanation has brought me in the right direction.
Thank you very much.
Best regards Frank