I am trying to prevent a button click method from executing when grid errors prevent focus change. When the grid has an error, I retain EditMode and the grid retains focus. However, the button click event still executes. The call stack indicates the focus change has triggered the grid.validating event which is cancelled and as expected the focus is retrieved to the grid. However then the MouseUp event seems to proceed and trigger the Button Click event.
I have an ultraGrid control nested in a user control nested in a second user control that also contains various buttons. I use IDataErrorInfo methods to show the error glyph when the cell is in error and retain EditMode. I have attached an event handler for both grid.Validating and the interior userControl.validating both set to cancel with an error. The user control has AutoValidate.EnablePreventFocusChange. I can't find a similar type of property for the ultraGrid. The buttons are set with AcceptsFocus, CausesValidation.
If i just use nested UserControls, set PreventFocusChange and cancel validation, the button click doesn't happen. It seems related to the state of the most nested container control.
Any suggestions appreciated.
Wendy
Hello Hristo
I have added an event handler for the UltraGrid.Validating event and cancel the event.. The event handler is being executed before the button click event handler. The grid does retain focus on error but the button click event handler is still being fired. The stack trace shows it's firing on the mouse Up event so perhaps the grid does not manage mouse capture or I need a workaround to test focus in the Button Click event handler.
Windows.Forms.ContainerControl.AutoValidate has an enumeration one of which is EnablePreventFocusChange.
Hello ,
I am not sure what is the PreventFocusChange property , I have searched in MSDN but I was not able to find any default PreventFocusChange property. However if you want to prevent the user to leaves the grid (disable to click onto other control) you should handle Validating event of the UltraGrid and to canceled the event (e.Cancel = true), based on your validation logic.
Please let me know if you have any further questions or if I am missing something.