Solved

DateTime picker and 'blank' entry

Posted on 2002-05-20
4
860 Views
Last Modified: 2013-11-20
I would like to use a DateTime picker control for entry of a date.  When it is a new entry I would like the control to display __.__.____ where the _ is a blank.
How does one do this?
0
Comment
Question by:AndyAinscow
  • 2
4 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hi!
You have to set DTS_SHOWNONE style to the desired DateTimePicker control and pass special value in the DTM_SETSYSTEMTIME message:
m_wndDateTime.SendMessage(DTM_SETSYSTEMTIME, GDT_NONE, NULL);
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
Comment Utility
Andy,
I'm not really convinced that this step is needed.  The control automatically dims the text when the checkbox has been cleared.  It seems to me that that should be a perfect visual clue to indicate "no date selected" (which I'm guessing is what you are aiming for here).

But setting the date to 0, really sets it to some arbitrary starting date back in 1969 or the year 100, (depending on how you do it).

If you really want to persist in this direction, you can try this:

In OnInitDialog, use this:

     m_ctlDateTime.SetFormat("  -  -    " );
(actually, this looks better)
     m_ctlDateTime.SetFormat("      -      -" );

But now you need to switch to a valid format whenever the user decides to input a date.  How you will do that will involve some other settings.  I am using the drop-down calendar, so I user the ClassWizard to add a handler for DTN_DROPDOWN). It looks like this:

void CMyDlg::OnDropdownDatetimepicker1(NMHDR* pNMHDR, LRESULT* pResult)
{
     m_ctlDateTime.SetFormat("dd-MM-yyyy" );
     *pResult = 0;
}

Now, as soon as the used drops-down the calendar, today's date appears so that the user can change it.  If you need to use the spin-buttons or allow user-editing, you will need to use some other notifications to learn when it is time to install a valid format string.

-- Dan
0
 
LVL 44

Author Comment

by:AndyAinscow
Comment Utility
Migel,
On my development system (Win 2000) the date still is displayed which is not what I desire.  Dan has guessed correctly what I intend.
0
 
LVL 44

Author Comment

by:AndyAinscow
Comment Utility
Thanks Dan, It's neat behaviour with the 'invalid' format.  I'll have to do some messing about as the user will usually type the date in which is not ecessarily todays date but your comment gives a good starting point.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now