2007-08-07

DateTimePicker and nullable value

Is it really that the simplest solution of bringing closer together DataBinding and nullable types is to change a behavior of a control itself?


class NullableDateTimePicker : DateTimePicker
{
[Bindable(true)]
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);
}
}
}

Though in the ideal case it should be solved at the databinding level instead of the custom control.

No comments:

Post a Comment