How to set today as the default date for a timer?

As properties The value of the date / time picker parameter does not allow you to enter the default DateTime.Now value, I tried to set it in the code:

Private Sub DataFrom_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DataForm.ValueChanged DataFrom.Value = DateTime.Now End Sub 

It really shows the current opening date of the form by choosing a date / time. However, you cannot set any other date from the drop-down calendar (you can select a date, which means that the calendar drops out, which allows you to specify the date, but after clicking on the selection, the date / time of the selection returns to the current date).

Thank you in advance for some testimony. Marek

+4
source share
3 answers

I believe that you are installing it in the wrong place. If you use the "Changed Value" event to set it, it will always change because you are overriding the value you just selected ...

You must set it in the Form Load method, where it will default to once.

+4
source

You need to set the value in the Form_Load event:

 Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load DataFrom.Value = DateTime.Now End Sub 
+2
source

You want to put this code in Form_Load :

 Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load DataFrom.Value = DateTime.Now End Sub 
+1
source

Source: https://habr.com/ru/post/1385016/


All Articles