title: Capturing first character on entering edit mode - custom editing control in DataGridView
body: <p>I'm hosting a custom editing control in a <code>DataGridView</code>, which for the record is a <code>TextBox</code> and <code>Button</code> together in a <code>UserControl</code>. I have inherited from <code>DataGridViewColumn</code> for the new column and <code>DataGridViewTextBoxCell</code> for the new cell.</p>
  
  <p>With a normal <code>DataGridViewTextBoxCell</code>, if you press a key when the cell has focus, it will begin edit mode <b>and</b> the character you typed will appear in the <code>TextBoxEditingControl</code>. However, in my inherited cell, no value is being passed down on keypress. (In fact, you have to manually pass the current cell value in <code>InitializeEditingControl</code> or nothing will show up at all.) So, the first character you type (the one that begins edit mode) is lost.</p>
  
  <p>I have tried <code>OnKeyPress</code>, <code>OnKeyDown</code>, and <code>OnKeyUp</code> in the <code>DataGridViewCell</code> but they never get called. <code>KeyEntersEditMode</code>, however, does seem to get called, and only when it is checking against a pressed key, so this might be a good place to start. The problem then becomes how to translate a KeyEventArgs to a <code>char</code>. This is trivial for alphabet and numbers, but since not all keyboards are created equal, handling other keys is messy and complicated at best. If there's a converter class that will do this automagically, please enlighten me.</p>
  
  <p>Has anyone else encountered this problem or found a good workaround?</p>
  
  <p>Note: This problem applies when <code>EditMode</code> is set to any variation of <code>EditOnKeystroke</code>. Setting to <code>EditOnEnter</code> is a valid workaround for my project, but I'd like to emulate the default behavior of the <code>TextBoxEditingControl</code> as well.</p>