I am trying to prevent the WinGrid from showing an error message when the user enters invalid data into a cell and then clicks the Cancel button on my form. To accomplish this, I tried setting the CausesValidation property of the button to False. This did not work because the actual validation of that cell does not occur within the Validate event of the grid control.
Since I can't use the CausesValidation property to prevent the error message from being displayed, is there any other way in which I can allow the grid to show the error message when the user clicks in another location, but don't show the error message when the user clicks the Cancel button on my form?
So the error event of the grid is firing in this case when you try to paste into a read-only cell, but setting e.Cancel to true is not stopping the error message from appearing?
If that's true, then it sounds like a bug to me and you should Submit an incident to Infragistics Developer Support so they can check it out.
The only alternative I see is that perhaps the BeforeMultiCellOperation event args have some properties to suppress the error message. But I don't think that's the case.
I'm trying to prevent the grid from showing an error when the user pastes data over cell(s) that have UltraGridCell.CanEnterEditMode = false. I want the error to be suppressed and the remaining cells to be pasted. I'm handling the Grid.Error event. In the help for MultiCellOperationErrorInfo class I found this:
Note: If you want to prevent the UltraGrid from displaying an error message, set the Cancel to true on the ErrorEventArgs. Alternatively you can also set the ErrorEventArgs.ErrorText to null or empty string to prevent the UltraGrid from displaying the error dialog. This lets you display a custom error message box.
That confirms what you said and the DataErrorInfo help makes mentions that e.Cancel can be used to suppress data errors. However, it isn't working. Here's my code (mangled on paste, sorry):
if (e.ErrorType == ErrorType.MultiCellOperation && e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste && e.MultiCellOperationErrorInfo.ErrorCell != null && !e.MultiCellOperationErrorInfo.ErrorCell.CanEnterEditMode) { e.MultiCellOperationErrorInfo.Action = MultiCellOperationErrorInfo.ErrorAction.Continue; e.ErrorText = null; e.Cancel = true;}
if (e.ErrorType == ErrorType.MultiCellOperation && e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste && e.MultiCellOperationErrorInfo.ErrorCell != null && !e.MultiCellOperationErrorInfo.ErrorCell.CanEnterEditMode) {
e.MultiCellOperationErrorInfo.Action = MultiCellOperationErrorInfo.ErrorAction.Continue; e.ErrorText = null; e.Cancel = true;
e.ErrorText = null;
e.Cancel = true;
}
I set breakpoints to confirm that the code is being hit. Note that if I set e.ErrorText = null, I get this exception:
An exception of type 'System.ArgumentNullException' occurred in Infragistics2.Win.UltraWinGrid.v8.1.dll but was not handled in user code. Additional information: ErrorText can not be null
An exception of type 'System.ArgumentNullException' occurred in Infragistics2.Win.UltraWinGrid.v8.1.dll but was not handled in user code.
Additional information: ErrorText can not be null
I'm using 2008.1.
Hi,
I don't know if what you are asking for is possible. You are correct that CausesValidation will not work here.
The grid's UpdateMode property determines when it tried to commit the value of a cell to the underlying data source. The question is, what exactly do you want to happen when the user clicks the Cancel button? All the grid knows at this point is that it is losing focus. It doesn't know that it's losing focus because a cancel button was clicked. It could be losing focus for any reason - the user could be clicking a save button or just moving to another control on the form. By the time the button click event fires, it will already be too late and the grid will have lost focus. So you really can't base what happens in the grid on what was clicked outside the grid.
If yu just want to cancel the error messages displayed by the grid, you can do this in the Error or CellDataError events of the grid. There are properties on the event args to allow you to choose whether or not the error messages are displayed. But cancelling the display of the error message doesn't prevent an error from actually occurring, so I'm not sure what will happen or what you want to happen beyond that.