I have a custom edit control in a DataGridView that for writing is a TextBox and Button together in a UserControl . I inherited from DataGridViewColumn for the new column and DataGridViewTextBoxCell for the new cell.
With a normal DataGridViewTextBoxCell , if you press a key when the cell has focus, it will start editing mode and the character you typed will appear in TextBoxEditingControl . However, in my inherited cell, no value is passed when the key is pressed. (In fact, you need to manually transfer the current cell value to InitializeEditingControl or nothing will appear at all.) So, the first character you enter (the one that starts editing mode) is lost.
I tried OnKeyPress , OnKeyDown and OnKeyUp in a DataGridViewCell , but they are never called. KeyEntersEditMode , however, does seem to trigger the call only when it checks for the key pressed, so this may be a good place to start. Then the problem arises of how to translate KeyEventArgs to char . This is trivial for the alphabet and numbers, but since not all keyboards are created equal, processing other keys is messy and complicated at best. If there is a converter class that does this automatically, please enlighten me.
Has anyone else encountered this problem or found a good workaround?
Note. This issue applies when EditMode is set to any EditOnKeystroke change. Installing in EditOnEnter is a valid EditOnEnter for my project, but I would also like to emulate the default behavior of TextBoxEditingControl .
source share