Question

After the focus leaves a TDateTimerPicker control and then at a later time returns to it, the control remembers which part (day, month or year) had the focus. Focus is returned to that part.

How can I force the focus back to the first per of the control?

Was it helpful?

Solution

To force the control to forget which part had the focus you can change the DateFormat and then change it back again. So if it is set to dfShort set it to dfLong and then back to dfShort.

The trick is not to do this after the focus returns via the OnEnter event, but to do it before the focus is returned.

So the best place to do this is in the OnExit event.

procedure TForm1.DateTimePicker1Exit(Sender: TObject);
begin

  DateTimePicker1.DateFormat := dfLong;
  DateTimePicker1.DateFormat := dfShort;

end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top