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?
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.
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.