Solved

DateTime picker and 'blank' entry

Posted on 2002-05-20
4
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 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