Sunday, August 15, 2004

Nullable Date Time Picker


A while back, i was so angry when i was using the .net c# dateTimePicker control on a winform. It did not support null dates. It defaulted to today's date. No matter if i push delete or anything.I decided to write a nullable one. I decided to write this one myself. Well, mostly myself.I got some ideas from usenet. Noone else had a solution that actually worked. I hope it works for you. BTW, in this control that inherits the date time picker, you must bind to BindMe, or else you will loose you null support.


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace DateTimePickerNull
{
       public class DateTimePickerNull 
: System.Windows.Forms.DateTimePicker
       {

              public DateTimePickerNull()
              {
                     this.ShowCheckBox=true;
              }

              public object BindMe

              {
                     get
                     {
                            if (this.Checked)
                            {
                                   return base.Value;
                            }
                            else
                            {
                                   return System.DBNull.Value;
                            }
                     }
                     set
                     {
                            if (System.Convert.IsDBNull(value))
                            {       
                                   this.Checked=false;
                            }
                            else
                            {       
                                   if (this.Checked==false)
                                          this.Checked=true;

                                   this.Value = Convert.ToDateTime(value);
                            }
                     }
              }

       }
}

5 Comments:

At 7:47 AM, Anonymous Anonymous said...

hi man
simple and good solution

thanks 4 help
Tom

 
At 10:31 AM, Anonymous Anonymous said...

Hey, thats great !!!
Finaly a version that works !!!
Now I have to bring it to a DataGridViewColumn.

Thanks a lot.

 
At 10:38 AM, Anonymous Anonymous said...

Thanks, I had searched all weekend for a solution that worked. Simple and easy to support.

 
At 1:50 PM, Blogger AHB said...

Hi I am new in C# could you please send me an example - how you use this class

 
At 8:31 PM, Anonymous aca said...

A even although back, i experienced been so angry when i experienced been utilizing the .net c# dateTimePicker control over a winform. It do not help null dates. It defaulted to today's date. No issue if i push remove or anything.I made a decision to compose a nullable one. I made a decision to compose this one myself. Well, primarily myself.I obtained some techniques from usenet. Noone else experienced a remedy that in fact worked. I wish it features for you. BTW, on this control that inherits the day time picker, you need to bind to BindMe, or else you will loose you null support.

cambridge fluro yellow satchel
cambridge satchel fluorescent yellow
cambridge batchel satchel
cambridge satchel company discount
women ugg boots on sale

 

Post a Comment

<< Home