C++/CLr for DateTimePicker, how to initialize the min time to today or time in future, and set the value programatically.

Greg Wilson-Lindberg 126 Reputation points
2022-11-16T01:55:33.987+00:00

I have two DateTimePickers. For the first one, I would like to set the min time to the current date & time when the program starts. But when I try to set MinTime in the properties using DateTime::Now, I get a "Property value is not valid" dialog, even though an example shows "dateTimePicker1->Value = DateTime::Now;". I can't edit the initialization of the properties, so without writing a custom setter for the date time it doesn't seem that there is a way to set this before the user sees the picker displayed.

I have a similar issue with a second DateTimePicker, I want the value set to a time in the future, but again, how do I initialize it at start up?

Developer technologies C++
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2022-11-16T02:35:11.237+00:00

    Hi, @Greg Wilson-Lindberg

    The snippet works for me:

    public:  
    	MyForm1(void)  
    	{  
    		InitializeComponent();  
    		//  
    		//TODO: Add the constructor code here  
    		//  
    		DateTime localDate = System::DateTime::Now;  
    		DateTime future=localDate.AddDays(12);  
    		dateTimePicker1->MinDate = System::DateTime::Now;  
    		dateTimePicker2->MinDate = future;  
    	}  
    

    260762-image.png

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.