To solve the exact same problem I took a bit of different approach. I wanted to leave the field as null if the user hadn't selected a date so I did this;
public class DBDateTimePicker:DateTimePicker
{
public DBDateTimePicker()
{
//
// TODO: Add constructor logic here
//
}
public object DBValue
{
get
{
if (this.Checked)
return base.Value;
else
return System.DBNull.Value;
}
set
{
if (System.Convert.IsDBNull(value))
this.Checked=false;
else
this.Value = Convert.ToDateTime(value);
}
}
}
Then I bind to “DBValue�nbsp; (instead of Value) and it appears to work fine�nbsp;if it is null, it is unchecked and disabled, otherwise it is enabled and can be set to any normal date value... if you uncheck the box yourself, then the data field is set to DBNull...
|