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
1960
Suppress error message based on other control's CausesValidation
posted

Hello,

I have a form with a grid, an Ok button and a Cancel button. Let's say the user is editing a cell and the current text is invalid. If the user clicks Ok there's a validation error and the grid keeps the focus. I can get that kind of behavior with no problem. Now if the user clicks Cancel I don't want any error message. Instead I want it to discard the current text in the cell and restore the original value, also the grid should give up the focus.

There are three issues here:

1) Identifying whether to display the error message or not: I tried to do this by setting the CausesValidation property of the Cancel button to false; for the Ok button I set it to true. I know the grid is not using the Validating and Validated events (see here) to trigger its internal validation, but my idea was detecting when the Validating error triggers (that happens when clicking the Ok button only) and only then the error message is displayed. The problem is when there's an invalid text the grid's Error event triggers before the Validating event, so I have no chance to determine validation is required. Instead I would expect the Validating event to trigger before the Error event. Is that a bug or that is working as intended?

2) I still havent' found a way to discard the current text in the cell and restore the original value (the one before starting editing). There has to be a way to do it programmatically because the user can do the same when hitting ESC.

3) Assuming there's a way to do 2), is there a way to handle the Error event so that the grid gives up the focus?

Parents
No Data
Reply
  • 40
    Verified Answer
    posted

    Hi,

    I stumbled upon the same problem. We have an UltraGrid where the contents of each cell needs to be validated immediately. The validation is currently performed in the BeforeExitEditMode event handler.

    Now we want to use the CausesValidation=false property to realize a Cancel button. Following workaround seems to work:

    All grids in our project had ExitEditModeOnLeave=true (default). I changed this to ExitEditModeOnLeave=false and added the following override in our control (which has UltraGrid as a base class):

    virtual void OnValidating(CancelEventArgs^ e) override {   PerformAction(Infragistics::Win::UltraWinGrid::
    UltraGridAction::ExitEditMode);
      __super::OnValidating(e);
    }

    As far as I see, this simply moves the Before-/AfterExitEditMode events from the Leave event to the Validating event. And now setting CausesValidation=false on the Cancel button allows us to leave the dialog even if the grid contains invalid data.

Children