hi, i have three portions of my question?
1) does datetimepicker picks up the current date of system automatically or not?
2) if it picks up so it does not show the current date to me on my form? why is it so?
Printable View
hi, i have three portions of my question?
1) does datetimepicker picks up the current date of system automatically or not?
2) if it picks up so it does not show the current date to me on my form? why is it so?
Nope, it won't pick it up by default.
.
When a DateTimePicker is created, it's Value is set to the current date and time. If you don't set the Value property explicitly, either in the designer or in code, then that's what it will display. I don;t understand your second question.
HI Jmcilhinney, its right that it picks up the default date and time, but when i change its value property so it shows the same. but the thing i want is that, I want that when my form is displayed so it always show the current date of the system? suppose after three months i execute my project so it does show me that date which will be after three month? how do i do this?
I'm afraid that I'm still not clear what you want. If you have a form with a DateTimePicker on it, when you display that form, it will show the current date and/or time in the control unless you set it to something else. If you want something else then set it to something else; if you don't then don't. Are you actually asking how to save the date/time between sessions?
*sigh* right... because you selected a date in the value property of the control... remove the date from the value property, let it reset itself and run the app again, this time DON'T select a date during design time.
-tg
hi techgnome, how it can be possible to keep the value property empty. this is not possible. when you leave the value property empty so it gives error that this is not valid value
I'm still not 100% sure what you're asking for but let me describe the way the DateTimePicker works and see if that provides the information you need.
The DateTimePicker is basically an interface to display a DateTime value and allow the user to change it. The most significant property is Value, which is type DateTime. It contains the value that is displayed to the user and, if the user enters a new value, the Value property is updated.
Because DateTime is a value type, the Value property must always have a value, i.e. it can never be "null" or Nothing. As with all value type fields and properties, if you assign Nothing to the DateTimePicker.Value property, it will use the default value for the type, which is 12:00 AM on 1/1/0001.
When a DateTimePicker object is created, the Value property is set to the current date and time by default. When you add a control to your form in the designer, it will display the current date and time at that moment. The Value will stay at that date and time until it has reason to refresh, e.g. you close the form and then re-open it. When you run the application, the DateTimePicker control gets created when the form is created. As such, the control will display the current date and time at that moment.
If you want the control to display a specific date and time then you must set the Value property to that value, either in the designer or in code. If you don't want it to display a specific date and time then don't set the Value property.
Now, as I said, the Value property must always have a value. As such, the control will always display a date and/or time. If you don't want a value displayed in the control then you can do it, but it's a bit fiddly. You need to set the ShowCheckBox property to True so that the control displays a check box. You can then use the state of that box, which corresponds to the Checked property, to determine whether the control represents a DateTime value or not. If Checked is False then you can set the Format property to Custom and the CustomFormat property to a string containing a single space character. The Value property will still contain a DateTime value but it won't be displayed to the user. You can then get a nullable DateTime value from the control like so:That's basically all you need to know about the DateTimePicker. If that doesn't answer your question then you're going to have to state more clearly what your question is. I assume that English is not your first language but you need to be clear. If you have to write a long post to do so then write a long post. Don't try to save yourself keystrokes at the expense of clarity. Providing too much information is better than providing too little.vb.net Code:
Dim actualValue As Nullable(Of DateTime) If myDateTimePicker.Checked Then actualValue = myDateTimePicker.Value Else actualValue = Nothing End If
It doesn't store the user's selection until you explicitly write the code to save it and restore it on the next loading.
So, if you want to keep the date value of the previous user remain unchanged, then you have to save that value to somewhere (say MySettings) and then next time, another user opens this form, you should have the code to load the previously saved value and display it in the DateTimePicker.
:wave: