By way of conclusion:
I have discovered that the SourceGrid does not have expected event handling for a grid, especially when it comes to handling focus. In addition to this fact, our code wrapper calls grid methods that reinvoke the focus events causing duplication.
What I have done, is added code to our wrapper to manage focus events properly. One other change I have made is to control the situation where the grid loses focus and causes a rowleave and rowchange event. To do this, I have resorted to disabling two lines of code in the SourceGrid.dll
The DataGridView is based upon the GridVirtual. In line 1849 of GridVirtual.cs I have made the following changes:
protected override void OnValidated(EventArgs e)
{
base.OnValidated(e);
//NOTE: I use OnValidated and not OnLostFocus because is not called when the focus is on another child control (for example an editor control) or OnLeave because before Validating event and so the validation can still be stopped
if ((Selection.FocusStyle & FocusStyle.RemoveFocusCellOnLeave) == FocusStyle.RemoveFocusCellOnLeave)
{
//Changed by CT - 2012-07-03
//Selection.Focus(Position.Empty, false);
}
if ((Selection.FocusStyle & FocusStyle.RemoveSelectionOnLeave) == FocusStyle.RemoveSelectionOnLeave)
{
//Changed by CT - 2012-07-03
//Selection.ResetSelection(true);
}
}
This basically means that when someone tabs or clicks away from the grid, no events are fired for the grid.
Ideally, it would be better to simply add code to our wrapper:
e.g. this.Selection.FocusStyle = FocusStyle.None;
and later switch back on with:
this.Selection.FocusStyle = FocusStyle.Default;
but it may be difficult to intercept the OnValidated event unless we use the grid.LostFocus event.
Comments, please?