Hi there
We using 13.1.20131.2040 of the UltraWinGrid in a VS 2010 .NET 4.0 C# WinForms app.
We are using the grids BeforeRowDeactivate event handler to perform validation and have noticed that the ClickCell event handler is never hit if we place a MessageBox in our validation within the BeforeRowDeactivate event handler.
Even when e.Cancel = false in the BeforeRowDeactivate event handler, if a MessageBox is used in that event handler then the ClickCell event handler is never hit but if we do NOT use a MessageBox then the ClickCell event handler is hit no problem.
What we are trying achieve is to validate/save in BeforeRowDeactivate, the user is prompted to save any unsaved data in that event handler, and if they do NOT wish to save to load child data for the next row in ClickCell
Is there a workaround to this?
Should I be using another event for validation or another event to load the data?
Sorry about not having a sample but our app is a pretty big beast and I have not as yet had a chance to create a sample to reproduce.
Regards
Geoff
Hi Geoff,
It's not uncommon for a MessageBox shown in certain grid events to interfere with the firing of other events, especialy mouse-related events. Showing a modal dialog takes focus away from the application so the mouse messages can get lost or be handled by the new dialog.
I'd recommend not showing a MessageBox inside of BeforeRowDeactivate, if you can. If you must do this, then try moving the MessageBox.Show call into a separate method and then using BeginInvoke to show it, instead of showing it from directly inside the event. That will create a delay so that the MessageBox shows after all of the event processing is complete.
void ultraGrid1_BeforeRowDeactivate(object sender, CancelEventArgs e) { UltraGrid grid = (UltraGrid)sender; grid.BeginInvoke(new MethodInvoker(this.ShowMessageBoxForBeforeRowDeactivate)); } private void ShowMessageBoxForBeforeRowDeactivate() { MessageBox.Show("Yoho"); }
Thanks Mike
Unfortunately I cannot really get around displaying a message box for the user to be prompted to save, disregard or remain on the current row when attempting to change rows.
Essentially our model is that if the user is navigating up/down the grid rows via keyboard we do NOT load the child data but as soon as the click on it we do load the child data. But when moving between rows if the user has changed and data then they are asked to Save or Reject the changes and move on OR cancel and remain on the row with the changed data.
The alternative of using BeginInvoke is also problematic in that we are using the ClickCell event to load child data for a row and when BeginInvoke is used it runs through to that ClickCancel event even if we set e.Cancel=true in the BeforeRowDeactivate event, obviously because of it's async design.
Can you tell me is there any publicly available event that fires prior to the BeforeRowDeactivate event (cancellable or otherwise)? I was thinking maybe I could test for row changes in that event and display messages in that event handler and then just use a flag to set the e.Cancel value in the BeforeRowDeactivate event.
Also is it possible to at all tell if in the BeforeRowActivate or AfterRowActivate event if the row was activated via a mouse click OR from a keystroke?