Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DateTime picker and 'blank' entry

Posted on 2002-05-20
4
Medium Priority
?
868 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 300 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 45

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 45

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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