Datagrid DateTimepicker column style

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, .Net experts,

I am using DatagridDateTimepickerColumn style posted on MSDN .net class
document in my datagrid. You can see the datagridDateTimepickerColumn style
at
http://msdn.microsoft.com/library/d...windowsformsdatagridcolumnstyleclasstopic.asp

It works fine with the datetimepicker column of current record in datagrid.
But when I click the very last record in datagrid (which creates a record), I
got an exception. I debuged it. It occured right after leaving Edit
function. Can somebody tell me the reasion and how to fix it?

Thanks,

Karl
 
Hi Karl
I am using DatagridDateTimepickerColumn style posted on MSDN .net class
document in my datagrid. You can see the datagridDateTimepickerColumn style
at:
http://msdn.microsoft.com/library/d...windowsformsdatagridcolumnstyleclasstopic.asp

It works fine with the datetimepicker column of current record in datagrid.
But when I click the very last record in datagrid (which creates a record), I
got an exception. I debuged it. It occured right after leaving Edit
function. Can somebody tell me the reasion and how to fix it?

The standard DateTimePicker control from .NET does not support null values.
Its value property must always be a valid DateTime value.

When you click on the last line in the datagrid and thus create a new
record, what happens with your DateTime value? Is it set to DateTime.Now?
Or is it initalized with null? If the latter, you would try to set the
DateTimePickers value property to null and that would raise an exception.

If that is the problem you should use a DateTimePicker control that
supports null values like this one:
http://www.codeproject.com/cs/miscctrl/NullableDateTimePicker.asp

hth
 
Back
Top