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 ,
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.
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.
Which version of Infragistics are you using ? I have tested your scenario with Infragistics 11.2 service release 2028. I have created a user control with UltraGrid and UltraButton in it. I handled Validating event of the UltraGrid and canceled the event if the red cell doesn’t contain 0 for value. So if the red cell contain a different value, Click events of my buttons are not raising. Please see the attached sample.
Please let me know if you have any further questions.
Hello Hristo,
Thanks for the sample. It works as you describe and the validating event prevents the click events as expected. Unfortunately, my scenario is a little different in that the grid is bound to a MbList and so the failure occurs at the cell binding level and cells will not ExitEditMode when invalid. To simulate this case in the sample, I added the BeforeExitEditMode event handler.
private void ultraGrid1_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e){
if (ultraGrid1.ActiveCell.Column.Index == 0 && (int)ultraGrid1.ActiveCell.Value != 0)
e.Cancel =
true; }
You will need to enter edit mode on the cell. Then clicking the button in the User control with the grid is prevented as the grid retains focus. Clicking the button on the form will execute the click event handler even though the validating event is cancelled and the grid retains focus. This is the behaviour I'm seeing in my application. (Note when testing that if there is a break in the code on the validating event handler, the button click will miss the MouseUp and not execute.)
Hello,
I am just checking about the progress of this issue. Is there anything else which I could do for you regarding this matter ?
Thank you for using Infragistics Components.
I've tried the sample and it works as you describe to prevent the button clicks. I now handle this Enter event in my application.
Regards,