Click here to Skip to main content
Click here to Skip to main content

Nullable DateTimePicker

By , 17 Nov 2003
 

Sample Image - Nullable_DateTimePicker.jpg

Introduction

I had do a research on a DateTimePicker that could enter null value and found a lot of solutions to it. But one major problem with those is that they behave quite different from the standard ones and may have many potential bugs, as a result it took time to test before using in a real application. I just found another simple solution that could solve this problem with a little modification, so it could promise no bugs :-).

Solution

I have overridden the Value property to accept Null value as DateTime.MinValue, while maintaining the validation of MinValue and MaxValue of the standard control. That's all there's to it.

Because it's so simple, there's not much to say about it. Please refer to code for details.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pham Minh Tri
Vietnam Vietnam
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNot able to download the Source Files [modified]memberhdng7631 Oct '12 - 5:00 
Hello There,
I am trying to download the source files, however I am not able to. When I clicked on the "Download Source Files" link, it routed me to the download page below. When I click on Nullable DateTimePicker link, it did not prompt me to save the file or anything. Do you know if the Souce Files are still available for download? If so, would you please show me how to download them? Any help is greatly appreciated!
File Download
Downloading Nullable_DateTimePicker_src.zip from the article Nullable DateTimePicker.
 
Note: If someone knows the answer, please put it in a new post as I don't have access to my email account from where I am right now.
Thanks much!!!!!

modified 31 Oct '12 - 11:42.

QuestionHow easy is that!!memberWoody10022 Sep '12 - 0:30 
I have spent half a day trying to determine why my search functionality was not working... I was trying to bind a null date to a datetimepicker... Interesting how this does not work...
 
Unless you have this excellent little control Smile | :)
 
Thank you for the Nullable Datetimepicker Smile | :)
QuestionJust what I neededmembergemini_dk20 Dec '11 - 4:43 
This is exactly the way I would like it to work.
I tweaked it a bit to be a nullable DateTime.
AnswerRe: Just what I neededmemberjf6425 Jan '12 - 4:57 
gemini_dk wrote:
This is exactly the way I would like it to
work.
I tweaked it a bit to be a nullable DateTime.

... then you should post your tweak for others...
 
Regards
GeneralNo hour in sql databasemembercyrilcp9 Nov '10 - 0:16 
It works!!! Thank's a lot.
If you don't want hour into your sql server field, add this and set datetimepicker format to 'short'
 
Public Shadows Property Value() As Object
Get
If MyBase.Checked Then
If MyBase.Format = DateTimePickerFormat.Short Then
Return MyBase.Value.Date
Else

Return MyBase.Value
End If
Else
Return System.DBNull.Value
End If
End Get
 
Set(ByVal Value)
If System.Convert.IsDBNull(Value) Then
MyBase.Checked = False
Else
MyBase.Value = Value
MyBase.Checked = True
End If
End Set
End Property
GeneralValidation wrong value fixmemberPREMSONBABY20 May '10 - 4:38 
Hi Guys,
 
I would like to thank to Pham Minh Tri, for this great work, and all the guys contibuted to fixing some issues. I would like to add a "small" fix to this. The problem is when you change the value its fireing the validators if you are using validators.
 

So as you can see i have added "IsInternalValueChanging", in your validator function just check this is true if its true, dont validate. Else you will get wrong value in your validator function.
 
public class DateTimePicker : System.Windows.Forms.DateTimePicker
{
private DateTimePickerFormat oldFormat = DateTimePickerFormat.Long;
private string oldCustomFormat = null;
private bool bIsNull = false;
 
private bool _valueChanging;
 
public bool IsInternalValueChanging
{
get { return _valueChanging; }
}
 
public DateTimePicker()
: base()
{
 
}
 
public new DateTime Value
{
get
{
if (bIsNull)
return DateTime.MinValue;
else
return base.Value;
}
set
{
 
if (value == DateTime.MinValue)
{
if (bIsNull == false)
{
oldFormat = this.Format;
oldCustomFormat = this.CustomFormat;
bIsNull = true;
}
 
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = " ";
base.OnValueChanged(new EventArgs());
}
else
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
 
if (value < this.MaxDate && value > this.MinDate)
{ base.Value = value; }
else if (value > this.MaxDate)
{ value = this.MaxDate; }
else if (value < this.MinDate)
{ value = this.MinDate; }
}
}
}
 
protected override void OnCloseUp(EventArgs eventargs)
{
base.OnCloseUp(eventargs);
 
if (Control.MouseButtons == MouseButtons.None)
{
if (bIsNull)
{
_valueChanging = true;
 
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
 
_valueChanging = false;
}
}
}
 
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyCode == Keys.Delete)
{
this.Value = DateTime.MinValue;
}
else if (this.Value == DateTime.MinValue || this.Value == null)
{
_valueChanging = true;
if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)
{
this.Value = DateTime.Today;
}
else if ((Char.IsNumber((char)e.KeyValue) && e.KeyValue != 48)
//<-- "0" correction
|| (e.KeyValue >= 97 && e.KeyValue <= 105)) //<-- NumPad1 - NumPad9
{
int typedDigit = 1;
if (e.KeyValue >= 97 && e.KeyValue <= 105) //<-- NumPad1 - NumPad9 must be calculated to numeric KeyValues
{
typedDigit = int.Parse(((char)(e.KeyValue - 48)).ToString());
}
else //if (Char.IsNumber((char)e.KeyValue))
{
typedDigit = int.Parse(((char)e.KeyValue).ToString());
}
this.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, typedDigit); //<-- this allows international format of the datetimepicker
SendKeys.Send(typedDigit.ToString()); //<-- this allows typing two digits at once without typing it again as example "12" or "27"
}
_valueChanging = false;
}
}
}
 

Regards,
Premson.
GeneralRe: Validation wrong value fixmemberoliwan30 Sep '10 - 12:16 
Hi,
 
I added a NullableValue property that allows data binding. I also added some code
to show the user when the control has the focus when the date is null (Nothing in
VB) by showing a "|" which looks almost like a cursor. I also improved the behavior
when the user starts typing in the empty field.
 
public class NullableDateTimePicker : DateTimePicker
{
	private DateTimePickerFormat _oldFormat = DateTimePickerFormat.Long;
	private string _oldCustomFormat;
	private bool _dateIsNull;
 
	private bool _isInternalValueChanging;
	public bool IsInternalValueChanging { get { return _isInternalValueChanging; } }
 
	public NullableDateTimePicker()
		: base()
	{
	}
 
	[Bindable(true)]
	[Category("Behavior")]
	[Description("The current nullable date/time value for this control")]
	public DateTime? NullableValue
	{
		get
		{
			if (_dateIsNull) {
				return null;
			}
			return base.Value;
		}
		set
		{
			if (value.HasValue) {
				Value = value.Value;
			} else {
				Value = DateTime.MinValue;
			}
		}
	}
 
	public new DateTime Value
	{
		get
		{
			if (_dateIsNull)
				return DateTime.MinValue;
			else
				return base.Value;
		}
		set
		{
 
			if (value == DateTime.MinValue) {
				if (!_dateIsNull) {
					_oldFormat = this.Format;
					_oldCustomFormat = this.CustomFormat;
					_dateIsNull = true;
				}
 
				this.Format = DateTimePickerFormat.Custom;
				this.CustomFormat = this.Focused ? "|" : " ";
				base.OnValueChanged(new EventArgs());
			} else {
				if (_dateIsNull) {
					this.Format = _oldFormat;
					this.CustomFormat = _oldCustomFormat;
					_dateIsNull = false;
				}
 
				if (value < this.MaxDate && value > this.MinDate) {
					base.Value = value;
				} else if (value > this.MaxDate) {
					value = this.MaxDate;
				} else if (value < this.MinDate) {
					value = this.MinDate;
				}
			}
		}
	}
 
	protected override void OnCloseUp(EventArgs eventargs)
	{
		base.OnCloseUp(eventargs);
 
		if (Control.MouseButtons == MouseButtons.None) {
			if (_dateIsNull) {
				_isInternalValueChanging = true;
 
				this.Format = _oldFormat;
				this.CustomFormat = _oldCustomFormat;
				_dateIsNull = false;
 
				_isInternalValueChanging = false;
			}
		}
	}
 
	protected override void OnKeyDown(KeyEventArgs e)
	{
		base.OnKeyDown(e);
		if (e.KeyCode == Keys.Delete) {
			this.Value = DateTime.MinValue;
		} else if (_dateIsNull) {
			_isInternalValueChanging = true;
			if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.Left) {
				this.Value = DateTime.Today;
			} else if ((Char.IsNumber((char)e.KeyValue) && e.KeyValue != 48) || (e.KeyValue >= 97 && e.KeyValue <= 105)) { //"0" correction, NumPad1 - NumPad9 
				int typedDigit = 1;
				if (e.KeyValue >= 97 && e.KeyValue <= 105) { //<-- NumPad1 - NumPad9 must be calculated to numeric KeyValues 
					typedDigit = int.Parse(((char)(e.KeyValue - 48)).ToString());
				} else { //if (Char.IsNumber((char)e.KeyValue)) 
					typedDigit = int.Parse(((char)e.KeyValue).ToString());
				}
				this.Value = DateTime.Now;
				SendKeys.SendWait("{RIGHT}"); // Selects the day part
				SendKeys.Send(typedDigit.ToString()); // Replaces the date part by the typed digit
			}
			_isInternalValueChanging = false;
		}
	}
 
	protected override void OnGotFocus(EventArgs e)
	{
		base.OnGotFocus(e);
		if (_dateIsNull) {
			CustomFormat = "|"; // Show the user that the NullableDateTimePicker has the Focus by simulating a cursor.
		}
	}
 
	protected override void OnLostFocus(EventArgs e)
	{
		if (_dateIsNull) {
			CustomFormat = " ";
		}
	}
}
--* Oli *--
www.cysoft.ch

GeneralRe: Validation wrong value fixmemberDeuceDude28 Oct '11 - 15:46 
thanks a lot to the original creator, and you two modifiers. logged in just to say that. This control being bindable is very helpful. note to others, remember to bind your datasource field/column to the "NullableValue" as opposed to the "Value"
 
[found under Data>(DataBindings) section in the "Properties Pane"]
Generalthank you for your help!memberwuhai08095 May '10 - 14:52 
thank you for your help!
GeneralSet Nullable DateTimePicker default value [00/00/0000]membertinhleduc26 Feb '10 - 0:27 
You can set NullFormat to [00/00/0000]
 
string _NullFormat = "00/00/0000";
public string NullFormat
{
get { return this._NullFormat; }
set { this._NullFormat = value; }
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown (e);
 
if (e.KeyCode == Keys.Delete)
{
this.Value = DateTime.MinValue;
this.ValueNullable = null;
//Backup CustomFormat
if (this.CustomFormat != _NullFormat) this._OldCustomFormat = this.CustomFormat;
this.CustomFormat = _NullFormat;
}
else
{
this.CustomFormat = this._OldCustomFormat; //Restore
}
}
protected override void OnValueChanged(EventArgs e)
{
base.OnValueChanged(e);
this.ValueNullable = base.Value;
}

http://www.sendspace.com/file/8qtjdj[Download Sample]
 
tinhleduc@gmail.com
GeneralUpdatememberRomain TAILLANDIER21 Sep '09 - 22:37 
Hello,
 
I use your code, because it is elegant, simple and efficient, as Phil Raevsky said.
I have used all remarks from the forum and found some new upgrades.
 
public class NullableDateTimePicker : System.Windows.Forms.DateTimePicker
{
    DateTimePickerFormat _Format;
    string _CustomFormat;
    private DateTime? _ValueNullable;
 
    public NullableDateTimePicker()
        : base()
    {
        _Format = base.Format;
        _CustomFormat = base.CustomFormat;
    }
 
    // overrides of this two property 
    // because in case of modifying Format or CustomFormat at runtime, saved values become obsolete, and could be restored

    public new DateTimePickerFormat Format
    {
        get { return base.Format; }
        set { this._Format = value; base.Format = value; }
    }
    public new string CustomFormat
    {
       get { return base.CustomFormat; }
       set { this._CustomFormat = value; base.CustomFormat = value; }
    }
 
    // using the nullable Datetime from alc_aardvark
    public DateTime? ValueNullable
    {
        get 
        { 
            // May be have to test this
            // if(_ValueNullable.HasValue && (_ValueNullable.Value <= this.MinDate || _ValueNullable.Value >= this.MaxDate))
            //     // do something
            return _ValueNullable; 
        }
        set
        {
            _ValueNullable = value;
            // Be carefull of limits, that cause ArgumentOutOfRangeExceptions
            // Limits are not from DateTime, but from this !
            // In this case Over range values, i do as if value was null (for printing)
            if(!_ValueNullable.HasValue || value <= this.MinDate || value >= this.MaxDate) 
            {
                // show nothing in datetime picker
                base.Format = DateTimePickerFormat.Custom;
                base.CustomFormat = " ";
                base.OnValueChanged(EventArgs.Empty);
            }
            else
            {
                // restore printing.
                base.Format = _Format;
                base.CustomFormat = _CustomFormat;
                base.Value = _ValueNullable.Value;
            }
        }
    }
 
    // Override this property to be sure ValueNullable is used.
    public new DateTime Value
    {
        get
        {
            if(!_ValueNullable.HasValue) // if( value == null)
               return this.MinDate; // or DateTime.MinValue
            return ValueNullable.Value;
        }
        set
        {
            this.ValueNullable = value;
        }
    }
 
    protected override void OnKeyDown(KeyEventArgs e) 
    { 
        ... //same as original version
    }
    protected override void OnCloseUp(EventArgs eventargs)
    { 
        ... //same as original version
    }
       
}
 
Hope that could help.
 
Romain TAILLANDIER
www.romaintaillandier.blogspot.com
romaintaillandier.free.fr
www.maintag.fr

GeneralThis is a very insightful approach to the problemmemberPhil Raevsky28 Aug '09 - 16:01 
Simple, elegant, and almost perfect
GeneralThis one dispaly pink if null date (VB.NET)memberLarry Rouse28 Aug '09 - 11:32 
Imports System
Imports System.Windows.Forms
Namespace Controls
Public Class DateTimePicker
Inherits System.Windows.Forms.DateTimePicker
Private bIsNull As Boolean = False
Private mBackColor As Color = SystemColors.Window
Public Sub New()
MyBase.New()
End Sub
Public Shadows Property Value() As DateTime
Get
If bIsNull Then
Return DateTime.MinValue
Else
Return MyBase.Value
End If
End Get
Set(ByVal value As DateTime)
If value = DateTime.MinValue Or value.Date = "01/01/1905" Or value.Date = "01/01/1900" Then
If bIsNull = False Then bIsNull = True
MakePinkFormat()
Else
MakeWhiteFormat()
bIsNull = False
MyBase.Value = value
End If
End Set
End Property
' Protected Overloads Overrides Sub OnCloseUp(ByVal eventargs As EventArgs)
Protected Overrides Sub OnCloseUp(ByVal eventargs As EventArgs)
 
If Control.MouseButtons = MouseButtons.None Or Control.MouseButtons = Windows.Forms.MouseButtons.Left Then
Me.Value = MyBase.Value
End If
MyBase.OnCloseUp(eventargs)
End Sub
Protected Overloads Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
MyBase.OnKeyDown(e)
 
If e.KeyCode = Keys.Delete Then
Me.Value = DateTime.MinValue
MyBase.Value = "01/01/1905"
End If
End Sub
Private Sub MakePinkFormat()
Me.Format = DateTimePickerFormat.[Custom]
Me.BackColor = Color.Pink
Me.CustomFormat = " "
MyBase.Value = "01/01/1905"
End Sub
Private Sub MakeWhiteFormat()
Me.Format = DateTimePickerFormat.Short
Me.BackColor = Color.White
Me.CustomFormat = Nothing
End Sub
'The BackColor property we will be calling
Public Overrides Property BackColor() As Color
Get
Return mBackColor
End Get
Set(ByVal Value As Color)
mBackColor = Value
'After the BackColor has been set, Invalidate the control
'This will force it to be redrawn
'Me.Invalidate()
End Set
End Property
'WndProc fires durring the painting of the control
Protected Overrides Sub WndProc(ByRef m As Message)
'Check to see if message being send is WM_ERASEBKGND.
'The hex value of this message is &H14.
'This message is sent when the background of the
'object needs to be erased. In our case though, instead of
'erasing it, we will paint a rectangle over it
If m.Msg = CInt(&H14) Then ' WM_ERASEBKGND
Dim g As Graphics = Graphics.FromHdc(m.WParam)
g.FillRectangle(New SolidBrush(mBackColor), ClientRectangle)
g.Dispose()
Return
End If
MyBase.WndProc(m)
End Sub
Private Sub DateTimePicker_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.EnabledChanged
Me.CalendarForeColor = Color.Black
End Sub
End Class
End Namespace
GeneralThis one works! (VB 2008) [modified]memberJeromeyers10 Feb '09 - 12:55 
This is an edit because I realized, like the previous poster, than you can simply shadow the Value property of the base DateTimePicker to allow Nullable Dates. That means that it works exactly like you would want/expect it to, in databinding situations and everything.
 
Public Class NullableDateTimeControl
    Inherits System.Windows.Forms.DateTimePicker
 
    Private oldFormat As DateTimePickerFormat = DateTimePickerFormat.Short
    Private oldCustomFormat As String = Nothing
    Private _IsNull As Boolean = False
 

    Public Sub New()
        MyBase.New()
    End Sub
 

    ''' <summary>
    ''' The Date Value of the control (is Nullable, can be set to Nothing).
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shadows Property Value() As Date?
        Get
 
            If Me._IsNull Then
 
                Return Nothing
 
            Else
 
                Return MyBase.Value
 
            End If
 
        End Get
        Set(ByVal newValue As Date?)
 
            If Not newValue.HasValue Then
 
                If Not Me._IsNull Then
 
                    Me.oldFormat = Me.Format
                    Me.oldCustomFormat = Me.CustomFormat
                    Me._IsNull = True
 
                End If
 
                Me.Format = DateTimePickerFormat.Custom
                Me.CustomFormat = " "
 
            Else
 
                If Me._IsNull Then
 
                    Me.Format = Me.oldFormat
                    Me.CustomFormat = Me.oldCustomFormat
                    Me._IsNull = False
 
                End If
 
                MyBase.Value = newValue.Value
 
            End If
 
        End Set
    End Property
 

    ''' <summary>
    ''' Allows the user to select a new date if the control is already null.
    ''' </summary>
    ''' <param name="eventargs"></param>
    ''' <remarks></remarks>
    Protected Overrides Sub OnCloseUp(ByVal eventargs As System.EventArgs)
 
        If Control.MouseButtons = Windows.Forms.MouseButtons.None Then
 
            If Me._IsNull Then
 
                Me.Format = Me.oldFormat
                Me.CustomFormat = Me.oldCustomFormat
                Me._IsNull = False
 
            End If
 
        End If
 
        MyBase.OnCloseUp(eventargs)
 
    End Sub
 

    ''' <summary>
    ''' Overrides the base class implementation to allow the user to create a Null value by pressing the Delete key.
    ''' </summary>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Overrides Sub OnKeyUp(ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyUp(e)
 
        If e.KeyCode = Keys.Delete Then
 
            Me.Value = DateTime.MinValue
 
        End If
 
    End Sub
 

End Class

 
modified on Wednesday, February 11, 2009 10:51 AM

GeneralRe: This one works! (VB 2008)memberEMYNA28 Oct '09 - 12:40 
Hi, i wanna know if this code can be used in visual studio 2008 (visual basic) or i need to make some changes to use them.
GeneralRe: This one works! (VB 2008) [modified]memberChris Wineinger13 Feb '13 - 8:31 
Thanks for this fine code Jeromeyers. I had to make a small modification to make the NullablePicker work. I changed OnKeyUp to set the _IsNull flag to True. (I also made the code responsive to the backspace key.)
  
Protected Overrides Sub OnKeyUp(ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyUp(e)
        If e.KeyCode = Keys.Delete OrElse e.KeyCode = Keys.Back Then
            Me._IsNull = True
            Me.Value = Nothing
        End If
End Sub

GeneralUse the Nullable Datetime for a more updated solution.memberchstngs7 Oct '08 - 5:39 
This way you can actually have a null value for the control.
 
public new DateTime ? Value
{
get
{
if (bIsNull)
return null;
else
return base.Value;
}
set
{
if (value == null)
{
if (bIsNull == false)
{
oldFormat = this.Format;
oldCustomFormat = this.CustomFormat;
bIsNull = true;
}
 
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = " ";
}
else
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
base.Value = value.Value;
}
}
}
 
protected override void OnCloseUp(EventArgs eventargs)
{
if (Control.MouseButtons == MouseButtons.None)
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
}
base.OnCloseUp (eventargs);
}
 
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown (e);
 
if (e.KeyCode == Keys.Delete)
this.Value = null;
}
GeneralIt's really great! Thank you very much!!memberwxpwu15 Jun '08 - 2:48 
Big Grin | :-D
GeneralSmall correctionmemberMaxxx33316 Nov '06 - 1:32 
When used out-of-the-box, the user must use the mouse to enter a date once the value has been set to DateTime.MinValue.
 
Change the KeyUp override as follows:
 
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
 
if (e.KeyCode == Keys.Delete)
this.Value = DateTime.MinValue;
 
else if (this.Value == DateTime.MinValue
&& (e.KeyCode == Keys.Space || Char.IsNumber((char)e.KeyValue)
|| e.KeyCode == Keys.Up || e.KeyCode == Keys.Down
|| e.KeyCode == Keys.Right || e.KeyCode == Keys.Left))
this.Value = DateTime.Today;
}
 
This allows the user to get the "normal" date in the box after pressing a space, any arrow key, or any number.
 
Comments?
GeneralRe: Small correction - an enhancement to that correctionmemberccbt9 Sep '09 - 19:27 
While this allowed the control to go back to edit mode after it was set to null, I didn't like the way it would go back to Today's date. The reason being... Today is 09/09/09. Well, lets say I want to go into that field and enter in an April date, I will hit 4 and it will display 09/09/2009. I will have to hit 4 again to enter the April date.
 
I tried moving the base.OnKeyUp(e) call after the code to set today's date so it would persist the 4 into the control and that didn't work. Then I tried moving the code to the OnKeyDown event handler. That didn't work either. So I found away around it be using some date manipulation:
 
        protected override void OnKeyDown(KeyEventArgs e)
        {
 

            if (e.KeyCode == Keys.Delete)
            {
                this.Value = null;
            }
            else if ((this.Value == DateTime.MinValue || this.Value == null)
                && (e.KeyCode == Keys.Space || Char.IsNumber((char)e.KeyValue)
                || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down
                || e.KeyCode == Keys.Right || e.KeyCode == Keys.Left))
            {
                DateTime newDate = DateTime.Today;
                if (Char.IsNumber((char)e.KeyValue))
                {
                    newDate = DateTime.Parse(string.Format("{0}/{1}/{2}", (char)e.KeyValue, DateTime.Today.Day, DateTime.Today.Year));
                }
                this.Value = newDate;
                
            }
            base.OnKeyDown(e);
 
        }
 
NOTE: I have also included a check for this.Value == null because I also altered the class to use a Nullable(DateTime). Also, this is in the OnKeyDown event. I moved this from the previously suggested OnKeyUp. I think it will work either way, though.
GeneralRe: Small correction - an enhancement to that correction BugFixing =) [modified]memberLeonunicorn4 Dec '09 - 1:45 
Hi there,
 
I have fixed some bugs and...
 
extended it to...
 
- use two digits
- international support
- using numpad
 
bugs fixed:
- using Zero "0" numeric exception
- always got april
- can't use two digits
- null value exception
 

       protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.KeyCode == Keys.Delete)
            {
                this.Value = DateTime.MinValue;     //<--- null does not work, so there is the origin value
            }
            else if ((this.Value == DateTime.MinValue || this.Value == null)
                && (e.KeyCode == Keys.Space || (Char.IsNumber((char)e.KeyValue) && e.KeyValue != 48)    //<-- "0" correction
                || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Right
                || e.KeyCode == Keys.Left
                || (e.KeyValue >= 97 && e.KeyValue <= 105) //<-- NumPad1 - NumPad9
                ))
            {
 
                int typedDigit = 1;
                if (e.KeyValue >= 97 && e.KeyValue <= 105)
                {//<-- NumPad1 - NumPad9 must be calculated to numeric KeyValues
                    typedDigit = int.Parse(((char)e.KeyValue - 46).ToString());
                }
                else
                {
                    typedDigit = int.Parse(((char)e.KeyValue).ToString());
                }
                
 
                DateTime newDate = DateTime.Today;
                if (Char.IsNumber((char)e.KeyValue))
                {
                    newDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, typedDigit);    //<-- this allows international format of the datetimepicker
                } 
                this.Value = newDate;
                SendKeys.Send(typedDigit.ToString()); //<-- this allows typing two digits at once without typing it again as example "12" or "27"
            }
            
            
        }

 
modified on Friday, December 4, 2009 9:02 AM

GeneralRe: Small correction - an enhancement to that correction BugFixing x 2 [modified]memberkipotlov11 Dec '09 - 6:14 
I got an exception on this line when i pressed space and the value is null :
 
typedDigit = int.Parse(((char)e.KeyValue).ToString());
 
I fixed it like this :
 
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.KeyCode == Keys.Delete)
            {
                this.Value = DateTime.MinValue;
            }
            else if (this.Value == DateTime.MinValue || this.Value == null)
 
            {
                if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down 
                    || e.KeyCode == Keys.Right || e.KeyCode == Keys.Left)                 
                {
                    this.Value = DateTime.Today;
                }
                else if ((Char.IsNumber((char)e.KeyValue) && e.KeyValue != 48) //<-- "0" correction
                    || (e.KeyValue >= 97 && e.KeyValue <= 105)) //<-- NumPad1 - NumPad9       
                {
                    int typedDigit = 1;
                    if (e.KeyValue >= 97 && e.KeyValue <= 105)    //<-- NumPad1 - NumPad9 must be calculated to numeric KeyValues        
                    {
                        typedDigit = int.Parse(((char)(e.KeyValue - 48)).ToString());
                    }
                    else //if (Char.IsNumber((char)e.KeyValue))
                    {
                        typedDigit = int.Parse(((char)e.KeyValue).ToString());
                    }
 
                    this.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, typedDigit); //<-- this allows international format of the datetimepicker

                    SendKeys.Send(typedDigit.ToString()); //<-- this allows typing two digits at once without typing it again as example "12" or "27"         
                }
            }
        }
 

 
modified on Friday, December 11, 2009 1:29 PM

GeneralRe: Small correction - an enhancement to that correction BugFixing x 2memberLeonunicorn15 Dec '09 - 4:57 
thanks =)
 
I have fixed an another issue too...
 
When you enter a date by keyboard and a MaxDate or MinDate is set, it will throw an exception.
 
I change the code again...
 

       public new DateTime Value
        {
            get
            {
                if (bIsNull)
                    return DateTime.MinValue;
                else
                    return base.Value;
            }
            set
            {
                if (value == DateTime.MinValue)
                {
                    if (bIsNull == false)
                    {
                        oldFormat = this.Format;
                        oldCustomFormat = this.CustomFormat;
                        bIsNull = true;
                    }
 
                    this.Format = DateTimePickerFormat.Custom;
                    this.CustomFormat = " ";
                }
                else
                {
                    if (bIsNull)
                    {
                        this.Format = oldFormat;
                        this.CustomFormat = oldCustomFormat;
                        bIsNull = false;
                    }
//MinMaxDate fix
                    if (value < this.MaxDate && value > this.MinDate)
                    {
                        base.Value = value;
                    }
                    else if (value > this.MaxDate)
                    {
                        value = this.MaxDate;
                    }
                    else if (value < this.MinDate)
                    {
                        value = this.MinDate;
                    }
                }
            }
        }

GeneralRe: Small correction - an enhancement to that correction BugFixing x 2memberLeonunicorn4 Jan '10 - 3:42 
I am back *smile*
 

Found a bug, when changing the DateTime Value to nothing (DateTime.MinValue) the ValueChanged Event will not be raised, so I put in an Eventraiser...
 

        public new DateTime Value
        {
            get
            {
                if (bIsNull)
                    return DateTime.MinValue;
                else
                    return base.Value;
            }
            set
            {
                if (value == DateTime.MinValue)
                {
                    if (bIsNull == false)
                    {
                        oldFormat = this.Format;
                        oldCustomFormat = this.CustomFormat;
                        bIsNull = true;
                    }
 
                    this.Format = DateTimePickerFormat.Custom;
                    this.CustomFormat = " ";
                    base.OnValueChanged(new EventArgs());   //Fix to raise a valuechange event when setting the DateTime Value to DateTime.MinValue (faked null)
                }
                else
                {
                    if (bIsNull)
                    {
                        this.Format = oldFormat;
                        this.CustomFormat = oldCustomFormat;
                        bIsNull = false;
                    }
 
                    //MinMaxDate fix
                    if (value < this.MaxDate && value > this.MinDate)
                    {
                        base.Value = value;
                    }
                    else if (value > this.MaxDate)
                    {
                        value = this.MaxDate;
                    }
                    else if (value < this.MinDate)
                    {
                        value = this.MinDate;
                    }
                }
            }
        }

QuestionNull Button?memberKysonel28 Mar '06 - 9:48 
I found this pretty usefull, but do you know a way to place a button in the calendar to place the null value? like the "today" button there is in the lower left corner... I'm using vb.net :P just so you know.
 
thanks!
QuestionHow to use?memberstrent0021 Dec '05 - 5:54 
The sample project doesn't work for me -- pressing delete does nothing. What gives?
 
How do I use this control in a project?
 
Relative performance is no substitute for absolute achievement.
GeneralCool!memberSuper Lloyd19 Dec '05 - 16:36 
I like it Wink | ;)
 
Actually change Value so it is a "DateTime?", much nicer
And also I used both Delete & Backspace for having an empty date
GeneralClicking on current date in dropdown doesn't show datetimememberjfk80@wp.pl15 Mar '05 - 2:38 
When NullableDateTimePicker (NDTP) state is null and it doesn't show value, click on the dropdown and select current value at the bottom of the dropdown, near red circle mark. This should change the NDTP state to not-null and show current DateTime. But NDTP checks if user selected value in dropdown by checking that no mouse button is pressed (in OnCloseUp), which is true only if a calendar was clicked, but not if bottom mark was clicked.
IMO, there is solution for this is not to rely on mouse button state in OnCloseUp. Instead override OnValueChanged and set a flag, then use it in OnCloseUp.
Thus:
 

protected override void OnCloseUp(EventArgs eventargs) {
if (Control.MouseButtons == MouseButtons.None || fHasValueChanged) {
if (fIsNull) {
this.Format = fOldFormat;
this.CustomFormat = fOldCustomFormat;
fIsNull = false;
}
fHasValueChanged = false;
}
base.OnCloseUp(eventargs);
}
protected override void OnKeyUp(KeyEventArgs e) {
base.OnKeyUp(e);
if (e.KeyCode == Keys.Delete) {
this.Value = DateTime.MinValue;
this.fHasValueChanged = false;
}
}
protected override void OnValueChanged(EventArgs eventargs) {
fHasValueChanged = true;
base.OnValueChanged(eventargs);
}

 
Resetting to false in OnKeyUp has to be done, because user can change value by hand, not by dropdown. In such case the flag remains true which could cause problems if user presses delete on NDTP and then pressed and depressed dropdown arrow (without changing value). If flag is not reset when she pressed delete, than suddenly NDTP would show value.

Generalbind data to date time pickermemberccloon20 Feb '05 - 22:11 
hi all,
 
i am using sql server and vb.net 2002 to develop my project.
the problem i face now is when i bind the null value (datatype = datetime) into the date time picker control, it show an error
 
please help, i need the code in vb.net
 
loon
 
Have a nice day
GeneralRe: bind data to date time pickermemberClaudio Grazioli28 Mar '05 - 10:36 
ccloon wrote:
i am using sql server and vb.net 2002 to develop my project.
the problem i face now is when i bind the null value (datatype = datetime) into the date time picker control, it show an error

 
Have a look at this version of a nullable date time picker.
http://www.omnitalented.com/Blog/PermaLink,guid,9ee757fe-a3e8-46f7-ad04-ef7070934dc8.aspx
It can handle "real" null values as you get them from databases.
 
You request it in VB. I'm sorry, it's in C#. But it's simple. I'm sure you manage to translate it.
 
Claudio Grazioli
http://www.grazioli.ch
GeneralRe: bind data to date time pickermemberClaudio Grazioli24 May '05 - 22:45 
As I already wrote you, this nullable DateTimePicker[^] can handle null values.
 
I created a VB.NET version of this control now and you can get it here: nullable DateTimePicker for VB.NET[^]
 
Claudio
Claudio's Website
Hommingberger Gepardenforelle
AnswerRe: bind data to date time pickermemberalc_aardvark14 May '08 - 6:07 
I tried this version and binding a nullable datetime does not work, as it leaves the last valid date from a previous bind. Here is a different version that seems to work better. NB. 5 minutes of testing only. Just dataBind to the ValueNullable property as opposed to the Value property if you have a Nullable DateTime. This should work as normal if you have a normal DateTime (bind to Value).
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
 
namespace Invisage.PinkFloyd.Library.Controls
{
public class DateTimePickerNullable : System.Windows.Forms.DateTimePicker
{
DateTimePickerFormat mOriginaldateTimePickerFormat;
private DateTime? mValueNullable;
 
public DateTimePickerNullable()
: base()
{
mOriginaldateTimePickerFormat = base.Format;
}
 
[Category("PinkFloyd")]
[Description("Nullable DateTime")]
[Bindable(true)]
public DateTime? ValueNullable
{
get { return mValueNullable; }
set
{
mValueNullable = value;
 
if (!mValueNullable.HasValue)
{
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = " ";
}
else
{
this.Format = mOriginaldateTimePickerFormat;
base.Value = mValueNullable.Value;
}
}
}
 

 
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown (e);
 
if (e.KeyCode == Keys.Delete)
{
ValueNullable = null;
}
}
}
}
GeneralRe: bind data to date time pickermemberRoonda6 Apr '09 - 19:13 
Have you tried pressing the Delete button when the ValueNullable it is bound? I think you'll find it doesn't work.
GeneralDisplay blank space when NULLmemberSupaHoopsa9 Feb '05 - 4:56 
Your control could possibly be what I am looking for.
 
I want to be able to display either a blank space or a customer phrase (such as "No Date Entered" when the date is NULL.
 
Can your control handle this?
GeneralRe: Display blank space when NULLmemberClaudio Grazioli19 Apr '05 - 22:16 
Have a look at this other DateTimePickers, they support that:
 
NullableDateTimePicker with DateTime.MinDate/DateTime.MaxDate[^] as null value.
 
NullableDateTimePicker with null[^] as null value.
 
Claudio
Claudio's Website
Hommingberger Gepardenforelle
GeneralThank youmemberjanine_olley12 Oct '04 - 4:37 
Thanks!
 
Just what I was looking for!
Thank you so much!
 
JanineBig Grin | :-D
General&quot;Error creating window handle error&quot; on TabControl controlmemberSMiLEZ28 Sep '04 - 8:11 
Hi Pham,
 
First off, excellent control. I have been looking far and wide for something like this, and I thought that I had found my solution in your control, but I am having difficulty placing it in a TabPage on a TabControl control AND data binding.
 
For example, if I start off with your DateTimePicker control in a TabPage container that is not by default displayed, no problem--I can choose the TabPage and it displays your control fine. Your control operates fine, and I can even set it to "null" (that is, DateTime.MinValue) before selecting the TabPage.
 
Now add databinding. If I have an additional private DateTime variable and in the form's Load event I add a custom databinding, e.g.
 

private DateTime dt = DateTime.MinValue;
 
private void Form1_Load(object sender, System.EventArgs e)
{
    this.dateTimePicker1.DataBindings.Add("Value", dt, "");
}

 
then, when I display the TabPage containing the control, I receive:
 
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.windows.forms.dll
 
Additional information: Error creating window handle.
 
Do you know any way to prevent this? Debugging seems to reveal that the error occurs somewhere in the Set clause, but I can't pinpoint it--very strange error.
 
Thanks!
Mark
GeneralRe: &quot;Error creating window handle error&quot; on TabControl controlmemberBrett Zimmerman5 Oct '04 - 16:00 
Yep - this one got me too!Cry | :((
 
It is the change in DateTimePicker.Format when you are switching between a null date and a non-null date (or vice versa). The change in the value of Format causes the component to raise a notification which is normally ok. But in the case you described above the control is not visible yet and the Format notification fails internally.
 
The work around is to leave the Format as Custom and switch the CustomFormat format between " " for a null date value, and the appropriate format for the date eg for short - "dd/MM/yyyy".
 
Cheers,
 
Brett
GeneralRe: &quot;Error creating window handle error&quot; on TabControl controlmemberClaudio Grazioli18 Apr '05 - 21:02 
SMiLEZ wrote:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.windows.forms.dll
 
Additional information: Error creating window handle.

 
If you're still looking for a solution to this problem, there is a new Nullable DateTimePicker on codeproject solving this problem.:
 
Yet another nullable DateTimePicker[^]
 
Claudio
Claudio's Website
Hommingberger Gepardenforelle
GeneralThanksmemberTom Fischer18 Jun '04 - 4:30 
Appreciate your handiwork!
GeneralCould you have vb.net versionmemberTony Dong25 May '04 - 11:10 
Hi there, I'd like to say that is very good idea, but could you convert it to vb.net version with the add function, may it help all people who need this one.
 
Sign In·View Thread·Permalink
GeneralNice control, but ...memberSachaMartineau25 Feb '04 - 3:38 
Did you try the case where u start with a null datetime ?
 
If you do that, you can't select anything anymore!
 
cheers ! Wink | ;)
GeneralRe: Nice control, but ...memberChristian Graus25 May '04 - 12:40 
Surely anyone who can't convert C# to VB.NET should consider a career as a plumber ?

 
Christian
 
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
GeneralRe: Nice control, but ...memberSteveHolland2 Feb '05 - 2:48 
Here is a VB.Net version.   In addition to allowing the date to be deleted (via F2 or Delete keys), the control's background color changes when it receives focus.
 
Public Class DateTimeControl
      Inherits System.Windows.Forms.DateTimePicker
      Private mdtmValue As Date = Now()
      Private mstrCustomFormat As String
      Private mdtpFormat As DateTimePickerFormat = DateTimePickerFormat.Long
      Private mblnSettoNull As Boolean
      Private mdtmMinValue As Date = DateTime.MinValue
      Private mstrText As String
      Private mBackBrush As SolidBrush
 
      <Description("Accepts legitimate date value or DateTime.MinValue."), MergableProperty(False), Category("Behavior")> _
      Public Shadows Property Value() As Date
            'This property definition overrides the Value property for the DateTimePicker control
            Get
                  'Return value stored in hidden variable
                  Return mdtmValue
            End Get
            Set(ByVal Value As Date)
                  'Set the hidden variable mdtValue
                  If mblnSettoNull = True Or Value = DateTime.MinValue Then
                        mblnSettoNull = False
                        mdtmValue = DateTime.MinValue
                  Else
                        mdtmValue = Value
                        MyBase.Value = mdtmValue
                  End If
            End Set
      End Property
      <Description("Accepts a legitimate date or time format string."), MergableProperty(False), Category("Behavior")> _
      Public Shadows Property CustomFormat() As String
            Get
                  Return mstrCustomFormat
            End Get
            Set(ByVal Value As String)
                  mstrCustomFormat = Value
                  MyBase.CustomFormat = mstrCustomFormat
            End Set
      End Property
      <DefaultValue(1), Description("Accepts a legitimate format such as Long, Short, Time or Custom."), MergableProperty(False), Category("Behavior")> _
Public Shadows Property Format() As DateTimePickerFormat
            Get
                  Return mdtpFormat
            End Get
            Set(ByVal Value As DateTimePickerFormat)
                  mdtpFormat = Value
                  MyBase.Format = mdtpFormat
            End Set
      End Property
 
Public Shadows Property BackColor() As Color
            Get
                  Return MyBase.BackColor
            End Get
            Set(ByVal Value As Color)
                  If Not mBackBrush Is Nothing Then
                        mBackBrush.Dispose()
                  End If
                  MyBase.BackColor = Value
                  mBackBrush = New SolidBrush(Me.BackColor)
                  Me.Invalidate()
            End Set
      End Property
      Protected Overrides Sub WndProc(ByRef m As Message)
            Const WM_ERASEBKGND As Int32 = &H14
            If m.Msg = WM_ERASEBKGND Then
                  Dim g As Graphics = Graphics.FromHdc(m.WParam)
                  If mBackBrush Is Nothing Then
                        mBackBrush = New SolidBrush(Me.BackColor)
                  End If
                  g.FillRectangle(mBackBrush, Me.ClientRectangle)
                  g.Dispose()
            Else
                  MyBase.WndProc(m)
            End If
      End Sub
      Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
            'Clear out when Delete of F2 is pressed
            If e.KeyCode = Keys.Delete OrElse e.KeyCode = Keys.F2 Then
                  mblnSettoNull = True 'Flag to indicate null value desired
                  Me.Format = DateTimePickerFormat.Custom
                  Me.CustomFormat = " "
                  Me.Value = DateTime.MinValue
            ElseIf e.KeyCode = Keys.Down OrElse e.KeyCode = Keys.Left OrElse e.KeyCode = Keys.Right OrElse e.KeyCode = Keys.Up Then
                  If IsNothing(Me.Tag) Then
                        Me.Format = DateTimePickerFormat.Custom
                        Me.CustomFormat = "MM/dd/yyyy"
 
                  Else
                        Me.Format = DateTimePickerFormat.Custom
                        Me.CustomFormat = "MM/dd/yyyy hh:mm tt"
                  End If
 
            End If
      End Sub
 
      Protected Overrides Sub OnCloseUp(ByVal eventargs As System.EventArgs)
            'This event fires when the user dismisses the graphical calendar
            Me.Format = DateTimePickerFormat.Custom
            If IsNothing(Me.Tag) Then
                  Me.CustomFormat = "MM/dd/yyyy"
            Else
                  Me.CustomFormat = "MM/dd/yyyy hh:mm tt"
            End If
            Me.Value = MyBase.Value
      End Sub
 
      Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
            Me.BackColor = System.Drawing.SystemColors.Window
      End Sub
 
      Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
            Me.BackColor = System.Drawing.Color.LightSteelBlue
      End Sub
End Class

QuestionOverrides value??memberEntLover12 Jan '04 - 3:32 
Hi, anyone knows how do I overrides the value property in the class? (im trying to translate the c# code)
 
I get a message saying that the property in the base class has not been declared as overridable so this won't work
 
vb.net
 
Public Overrides Property Value() As DateTime
Get
 
End Get
Set(ByVal Value As DateTime)
 
End Set
End Property
 
Could you please reply to
pietrud@hotmail.com
 
Thanks a bunch!

AnswerRe: Overrides value??sussUDALO17 Feb '04 - 6:39 
It's not an override : you have to mask the original property (in C# it's done with the new keyword; in VB.NET, it is Shadows;
For instance, this piece of code does nothing, but it works Smile | :) :
 
Public Class MyDateTimePicker
Inherits DateTimePicker
 
Public Shadows Property Value() As DateTime
Get
Return MyBase.Value
End Get
Set(ByVal Value As DateTime)
Value = MyBase.Value
End Set
End Property
End Class
 

GeneralAdd ShowUpDown property supportsussetranger2 Jan '04 - 17:11 
You can add support to the ShowUpDown property usually used for Time Format:
 
protected override void OnMouseUp(MouseEventArgs e)
{
if(this.ShowUpDown)
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
this.Value = DateTime.Now;
bIsNull = false;
}
}

base.OnMouseUp(e);
}
GeneralFiring OnValueChangedmemberSébastien Lorion26 Dec '03 - 15:38 
Your solution is simple and elegant, but two corrections should be made I think :
 
1- use OnKeyUp instead of OnKeyDown, because the latter is fired up repeatedly until the user releases the key.
 
2- You should fire up OnValueChanged manually when setting value to DateTime.MinValue. Here is the modified code :
 
public new DateTime Value 
{
	get 
	{
		if (bIsNull)
			return DateTime.MinValue;
		else
			return base.Value;
	}
	set 
	{
		if (value == DateTime.MinValue)
		{
			if (bIsNull == false) 
			{
				oldFormat = this.Format;
				oldCustomFormat = this.CustomFormat;
				bIsNull = true;
			}
 
			this.Format = DateTimePickerFormat.Custom;
			this.CustomFormat = " ";
			
			// fire up OnValueChanged manually
			base.OnValueChanged(new EventArgs());
		}
		else 
		{
			if (bIsNull) 
			{
				this.Format = oldFormat;
				this.CustomFormat = oldCustomFormat;
				bIsNull = false;
			}
			base.Value = value;
		}
	}
}

 
Sébastien
 


Intelligence shared is intelligence squared.
 
Homepage : http://www.slorion.webhop.org
GeneralRe: Firing OnValueChangedmemberBalaji Vishnumolakala4 Nov '04 - 4:07 
How can I set the cursor in the DateTimePicker control, which indicates focus on this control to user, after setting its value to null, and tabbing to it from other controls?
GeneralSelecting the control with TabmemberMortens_HUN7 Mar '07 - 0:47 
Hi all! I want to select this control with tab, and I found a solution, but I think it not the best. If somebody have an idea, share it with me please.
 
Here is the solution:
 
public new DateTime Value
{
get
{
if (bIsNull)
return DateTime.MinValue;
else
return base.Value;
}
set
{
if (value == DateTime.MinValue)
{
if (bIsNull == false)
{
oldFormat = this.Format;
oldCustomFormat = this.CustomFormat;
bIsNull = true;
}
 
this.Format = DateTimePickerFormat.Custom;
//this.CustomFormat = this.Format.toString();
this.CustomFormat = "yyyy";
base.OnValueChanged(new EventArgs());
}
else
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
bIsNull = false;
}
base.Value = value;
}
}
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 18 Nov 2003
Article Copyright 2003 by Pham Minh Tri
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid