I want to use the Editor for Grid and standard control like the UltraTextEditor. There is an extra function in the editor. The editor excepts numbers and certain characters and for these characters it does some computation.
I don't want to duplicate the logic and so looking to create a derived class. Since key handling overrides are not handled by UltraTextEditor derived class when used with Grid (column.EditorControl = myControl, has to be some grid event not control override). I created EditorWithText derived control. I was looking to override the OnOwnerKeyPress to handle key input. This is not working and I am sure it is because of lack of understanding of the EditorControl and Editor setup model.
public class SpecialEditorWithText : EditorWithText { protected override void OnOwnerKeyPress(System.Windows.Forms.KeyPressEventArgs e) { //If the key stroke is already handled if (!e.Handled) { if (!char.IsDigit(e.KeyChar) || e.KeyChar.Equals('C') || e.KeyChar.Equals('H')) { e.Handled = true; } } base.OnOwnerKeyPress(e); } } public class SpecialEditor : UltraTextEditor { private readonly SpecialEditorWithText m_editor = new SpecialEditorWithText(); public override EmbeddableEditorBase Editor { get { return m_editor; } } }
public class SpecialEditor : UltraTextEditor { private readonly SpecialEditorWithText m_editor = new SpecialEditorWithText(); public override EmbeddableEditorBase Editor { get { return m_editor; } } }
I am not clear with the Owner concept, is UltraTextEditor the owner of EditorWithText when used as control on the form AND is Grid the owner of EditorWithText when used with Column.Editor context ?
Is there any other option to avoid duplication of logic ?
Hi,
I don't think there's any way to do this via an editor. The Owner in this case is the grid column, but I don't think that the key action will always go through OnOwnerKeyPress and other methods like that. That only happens under certain circumstances. If the cell is in edit mode, the editor will be getting the messages directly and handling them via it's own internal TextBox control.
So there's really no way to do this with an editor. If you want to avoid duplicating logic, then my advice is to create a method that validates the key and call that method from both the grid's Key events and the ke events of any standalone controls you may need.