Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
17259
Error with a DateTime column in a new grid row
posted

Hi,

I have a column which is binded to a datetime field in an object. The Column style is "Date" and the data type is "System.DateTime".

Whenever I try to add a new row and I press the drop down button to see the calendar I get the following exception:

System.ArgumentOutOfRangeException: Value of '01/01/0001' is not valid for 'SelectionEnd'. 'SelectionEnd' must be greater than or equal to MinDate.
Parameter name: SelectionEnd

After I press on "Continue" I see the value 01/01/0001 in the cell.

Maybe setting the default value to today might solve it, but how do I do it?

Thanks

Parents
  • 725
    posted

    I would have to say that the problem is with your bound object, not the grid per se.  Since DateTime is a value type, not a reference type, it always holds some value and can never be null (Nothing in VB).  You may try using a 'Nullable(of DateTime)' field rather than a datetime field.  The Nullable structure encapsulates a value type and allows you to treat it (sort of) as a reference type instance.  So your field can have a value of null (or Nothing).  Otherwise, I'm not really sure how the grid will handle this.  I always bind to DataTable objects (which of course allow DBNull for column values).

     If you do want to have the value of Today be the default then I suppose you would want to include that as part of the constructor on your object.

Reply Children