This project has moved and is read-only. For the latest updates, please go here.

Enter key in DateTimePicker

Nov 15, 2011 at 7:57 PM

The DateTimePicker, when set in editable mode, prohibits the processing of Enter key from bubbling up - it sets e.Handled = true. This could be an issue when using it as cell editor for DataGrid. The standard DataGrid(from Microsoft) is to hit Enter key to commit and Escape key to abort the change. Is there any workaround so that the KeyDown event for Enter key gets bubble up when the DateTimePicker is editable?


Nov 16, 2011 at 4:13 PM

To be honest, I  do not take the DataGrid into consideration when developing the controls.  My suggestion would be to either derive from the DateTimePicker and override the OnPreviewKeyDown event or download the source and modify the source code.

Nov 16, 2011 at 5:54 PM

I don't know if the "derive" approach will work as there is private instance variable in the OnPreviewKeyDown event handler in DateTimeUpDown.cs. Don't really want to modify the source code as I have to keep up with every new release. I opt to use the AddHandler method with HandledEventsToo set to true. It seems to work fine so far. That way, I still have the chance to handle the Enter key and then artificially create another KeyDown event in code so that the DataGrid can get it. Any thought?

Nov 16, 2011 at 7:02 PM

Seems like a good solution to me.