Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I want to save a Custom DateTimePicker.Value in my Application Settings.
The custom format is : dd/MM/yyyy hh:mm:ss, instead of dd/MM/yyyy
The field i've created in the application settings parameters is LASTSAVE (DATE / APPLICATION)

When I try to link in the ApplicationSettings/PropertyBinding ... VALUE with my field LASTSAVE, i have an error :

The Value '01/01/0001 00:00:00' is not valid for 'Value'. 'Value' must be ... 'MinDate' et 'MaxDate'.

Name of the parameter : Value


I then entered the MIN and MAX date in the properties of my control DATETIMEPICKER. I have also put into the properties Value a start date like 23/11/2011 12:00:00 ;

However, when i retry to link in the ApplicationSettings/PropertyBinding ... value to LASTSAVE / I have the same error (The Value '01/01/0001 00:00:00' is not valid for 'Value'. ). I've saved all, do a process that put a value in the datetimepicker.value, but it's not saved, cause not linked.

A solution please ?
Posted

1 solution

Don't save date and/or time values as strings; use System.DateTime[^] variables. In that way it will be valid for every system in the world; only when you need to display the value do you need to convert it to a readable string.
 
Share this answer
 
Comments
contact97438 24-Nov-11 5:38am    
Hello Richard,

I do not use a string value, but a datetimepicker, and a field "LastSave" which is a Date Type.

Private Sub TimerSauvegarde_Tick(sender As System.Object, e As System.EventArgs) Handles TimerSauvegarde.Tick
'Dim LastSave As DateTime = Convert.ToDateTime(My.Settings.DateDernièreSauvegarde)

Dim LastSave As DateTime
Dim NextSave As DateTime
LastSave = Nothing
NextSave = Nothing

LastSave = My.Settings.LastSave

'MsgBox(LastSave)

Dim Hour, Minute As Decimal
Hour = My.Settings.Heures
Minute = My.Settings.Minutes

Select Case ComboBoxA_Toutes.Text
Case "A" 'At a specific time of the day
NextSave = DateAdd(DateInterval.Hour, Hour, Today)
NextSave = DateAdd(DateInterval.Minute, Minute, NextSave)
'MsgBox("LastSave : " & LastSave & "Hour" & Hour & "Minute = " & Minute & "Next Save at : " & NextSave)
Case "Toutes les" 'Every Hours/Minutes specified by the user
NextSave = DateAdd(DateInterval.Hour, Hour, LastSave)
NextSave = DateAdd(DateInterval.Minute, Minute, NextSave)
'MsgBox("LastSave : " & LastSave & "Hour" & Hour & "Minute = " & Minute & "Next Save at : " & NextSave)
End Select

If NextSave <= Now Then
ButtonSauvegarder.PerformClick()
'MsgBox("Déclenche une sauvegarde automatique")
End If
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900