Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Activated   Event   Time    Duration    Thread    
    Exception thrown: 'System.ArgumentOutOfRangeException' in System.Windows.Forms.dll ("Value of '1.1.0001. 00:00:00' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.")   14.33s      [17640] <No Name> 


What I have tried:

// don't convert it to datetime (as you said, it may be null)
                var stringValue = (prijava_radnikaDataGridView.SelectedRows[0].Cells["dataGridViewTextBoxColumn3"].Value);


                 var dateValue = string.IsNullOrEmpty(Convert.ToString(stringValue)) ? DateTime.MinValue : Convert.ToDateTime("2018-01-01 00:00:00");

               // now, datevalue is the new value for datepicker
                  if (string.IsNullOrEmpty(Convert.ToString(stringValue))) vrijemeodjaveDateTimePicker.Value = dateValue;
Posted
Updated 27-Mar-18 18:09pm
Comments
Maciej Los 25-Mar-18 14:53pm    
Coould you be more specific and provide more details about your issue?
This piece of code explains nothing...

I don't think you can remove totally the default minimum and maximum values for DateTimePicker.
You can however set it to be between whatever value you wish as long as values are between both extremes and the minimum value is not greater than the maximum value.

You may want to use the value of
C#
DateTimePicker.MinDateField
instead of
C#
DateTime.MinValue
as they have separate minimum values.

References:

DateTimePicker.MinDate Property (System.Windows.Forms)[^]

DateTimePicker.MinDateTime Field (System.Windows.Forms)[^]
 
Share this answer
 
The Windows DateTimePicker returns a DateTime value.
DateTime values in C# value types hence cannot be null. Only reference Types can be null.
You can create a Nullable DateTime control - or purchase one of the commercially available ones - refer to the following CodeProject links;
Nullable DateTimePicker[^]
Yet another nullable DateTimePicker control[^]

Kind Regards
 
Share this answer
 

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