I tried to change the default time from 12:00AM to 09:00AM when user types the first character in the date Edit.
private void dateEdit1_KeyDown(object sender, KeyEventArgs e)
if (dateEdit1.DateTime == DateTime.MinValue)
dateEdit1.DateTime = System.DateTime.Today.AddHours(9);
However, after change the date through KeyDown, the dateEdit does not work. It only accepts the first digits for DD, user clicks 11, it only display 1. user click 12, it display as 2. Same thing for MM, YYYY and others.
Enter event works fine but we want the user to type inside the control to avoid user uses TAB KEY to create dummy data.
Please advice. Thanks,
Thank you for your question.
This behavior is by design. After accessing the DateEdit.DateTime and DateEdit.Edit value properties, currently pending edit actions are flushed. This logic is implemented to prevent the saving or returning of possibly incomplete data. To accomplish this task, I suggest you handle the DateEdit.KeyPress event, set the DateEdit.DateTime value as your needs dictate, and set the KeyPressEventArgs.Handled property to True. I have created a sample project to demonstrate this approach in action. Please let us know whether or not this solution meets your requirements. If not, feel free to reactivate this ticket.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.