Category / Section
How to Auto-Select initial field in the DateTimePickerAdv once it is focused?
1 min read
The null value of the DateTimePickerAdv is not set, by default. It can be set to DateTimePickerAdv by enabling the property, IsNullDate. When Date value is set as null date, the property NullModeKeyReset is set to ArrowKeys, by default.
The NullModeKeyReset property helps you define the keyboard navigation of the DateTimePickerAdv. When the date value is changed by keyboard navigation, the field of the DateTimePickerAdv changes continuously.
It is possible to AutoSelect the initial field or date value once it is focused by using its property named ResetSelectionOnFocus.
The following code example demonstrates the same.
C#
//Sets the selected value as Null. this.dateTimePickerAdv1.IsNullDate = true; //Gets or sets the keys that toggles off null date. this.dateTimePickerAdv1.NullModeKeyReset = NullModeKeyReset.NumericKeys; //Focuses the DateTimePickerAdv selection on the first field. this.dateTimePickerAdv1.ResetSelectionOnFocus = true;
VB
'Sets the selected value as Null. Me.dateTimePickerAdv1.IsNullDate = True 'Gets or sets the keys that toggles off null date. Me.dateTimePickerAdv1.NullModeKeyReset = NullModeKeyReset.NumericKeys 'Focuses the DateTimePickerAdv selection on the first field. Me.dateTimePickerAdv1.ResetSelectionOnFocus = True
Figure 1: Before selecting the date
Figure 2: After selecting the date