c# - Return a null value from date control

c# - Return a null value from date control

am 11.01.2008 14:07:45 von nologo

Hi,

Visual Studio 2005, C#.net

I wish to return a NULL value from a date control if no date is
selected. Anyone got any idea on how i would do this?


Cheers

Re: c# - Return a null value from date control

am 11.01.2008 14:22:21 von Marc Gravell

If I unsderstand... well, if you are using binding to a nullable
datetime (i.e. "DateTime?"), then it should just work automatically;
otherwise, check for DateTime.MinValue and substitute for your NULL.
In the other direction there is also a NullValue on a binding, which
is the value to display when the source is null.

Marc

Re: c# - Return a null value from date control

am 11.01.2008 14:28:20 von nologo

Thanks for reply Marc, the DateTimePicker control has a mindate value
that only allows for the date format to be entered...so for example,
trying to return the value as NULL gives an error.
The mindate has a value preassigned in the date format

Re: c# - Return a null value from date control

am 11.01.2008 14:42:01 von Marc Gravell

In that case, perhaps use the ShowCheckBox to indicate that no date
should be used, and look at .Checked as well as .Value?

Marc