?
Solved

DateTime picker and 'blank' entry

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 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