none
How to control focus in CDateTimeCtrl RRS feed

  • Question

  • Hi,

      When using the CDateTimeCtrl as a time (or Date), the control remembers the last place data was entered.  For example, if you entered "12:30", the next time you tab into this field, the focus in on the seconds field or "30".  I have tried ::PostMessage(m_hWnd, WM_KEYDOWN, VK_LEFT, 0) in the ON_NOTIFY(SETFOCUS...) but these keystrokes appear to be ignored at this point.  Any ideas how to get control over which field has focus?

    Thanks,

    Bill

     

    Friday, April 16, 2010 3:55 PM

Answers

  • Here is one way I got around this limitation:

    catch the NM_KILLFOCUS message for the data time control and in the handler change the format of the time control like this:

    m_TimeCtrl.SetFormat(_T("hh")); //set it to a format that only has one field

    m_TimeCtrl.SetFormat(_T("hh:mm:ss tt")); //set back to normal

     

    This changes the format to a single field format, which forces the focus to go back to the first field, and when you change the format back to normal the focus is still on the first field.

     


    Ali
    • Marked as answer by bill sontag Friday, April 16, 2010 5:30 PM
    Friday, April 16, 2010 5:16 PM

All replies

  • Here is one way I got around this limitation:

    catch the NM_KILLFOCUS message for the data time control and in the handler change the format of the time control like this:

    m_TimeCtrl.SetFormat(_T("hh")); //set it to a format that only has one field

    m_TimeCtrl.SetFormat(_T("hh:mm:ss tt")); //set back to normal

     

    This changes the format to a single field format, which forces the focus to go back to the first field, and when you change the format back to normal the focus is still on the first field.

     


    Ali
    • Marked as answer by bill sontag Friday, April 16, 2010 5:30 PM
    Friday, April 16, 2010 5:16 PM
  • Thanks Ali!  It works great and keep the previously set time.
    Friday, April 16, 2010 5:32 PM