Solved

DateTime picker and 'blank' entry

Posted on 2002-05-20
4
861 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
ID: 7021052
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
ID: 7023036
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
ID: 7023595
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
ID: 7023604
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doc'in system (example?) BA 7 86
sum28 challenge 31 105
Detect file exist or not 3 127
how to split multiple lines delimiter : 8 77
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 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

12 Experts available now in Live!

Get 1:1 Help Now