Thank you for the sample code; it is just what I needed. However there appears to be a problem if you enter a one-digit month or day and then press Enter or Tab. Focus leaves the cell but the cell contents revert to the original value. If you change the value and then move with arrow or "/" before pressing Tab or Enter, or if you enter a two-digit month or day, then the changed value is stored. I tried trapping EditingControlWantsInputKey, OnValueChanged and OnKeyDown for the Control, but they don't fire on Tab or Enter. They didn't seem to fire on the grid or form either. Any suggestions on how to ensure changes are kept when Tab or Enter is pressed in CalendarEditingControl?
[2009-06-22]
After querying Microsoft Support about this, they mentioned a KB article related to this problem and suggested trapping the Enter and Tab keys using ProcessCmdKey. Since there is varying behavior when Ctrl, Alt or Shift is pressed with Enter and Tab, I handle all those with the following code:
/// <summary>
/// Processes a command key
/// </summary>
/// <param name="msg">A <see>Message</see>, passed by reference, that represents the window message to process</param>
/// <param name="keyData">One of the <see>Keys</see> values that represents the key to process</param>
/// <returns>true if the character was processed by the control; otherwise, false</returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
// If [Ctrl|Alt|Shift] Enter or Tab key pressed, set focus to the hosting Grid control to force data to be validated
// This fixes a problem when [Ctrl|Alt|Shift] Enter or Tab pressed after a one-digit value is typed by user
// See http://support.microsoft.com/kb/822498 for details
switch (keyData & Keys.KeyCode)
{
case Keys.Enter:
case Keys.Tab:
dataGridView.Focus();
break;
}
return base.ProcessCmdKey(ref msg, keyData);
}