Click here to Skip to main content
Email Password   helpLost your password?

Introduction

This article describes an extension of the MS DateTimePicker.

Background

I developed this control to meet the needs of a client. In a database application I am developing, my clients requirements are that I display dates and times as blank, unless a valid date or time is entered. Additionally they wanted to display a separate field with the day of the week associated with the date entered, and also dates with an associated AM or PM, but no specific time.

To achieve this I built a composite control based on the DateTimePicker class.

The control sub classes the System.Windows.Forms.DateTimePicker control, and I added a TextBox to the DateTimePicker so that it sits in front of the DateTime display area, and allows the user to enter a date and or time, and which displays the date and or time according to the format Selected. A Tooltip object and an ErrorProvider were also included with the control. I may have gone a little overboard with the format options, but a couple of the stranger ones are necessary for me to display the data the way the client wants.

To begin with, I overrode the DateTimePicker's standard Format property, set it to Browsable(false) and gave it a single accessor get, which returns base.Format. The standard Format property is no longer available in the Properties Window, and it cannot be set external to the new control.

Next I defined a new property FormatEx, which is browsable and is of Type enum dtpCustomExtensions, which is an enumeration of all the possible date and time formats this control handles as standard. They include dtpLong, dtpShort, dtpTime and dtpCustom, which provide duplicate functionality to the standard Long, Short, Time and Custom attributes formerly selectable from the Format Property. The standard Format property is set permanently to Custom.

InitialiseCustomMessage() is called whenever FormatEx is set to a new value, InitialiseCustomMessage() sets the appropriate message in the Tooltip, to be displayed when the mouse hovers over the control.

FormatTextBox() is called whenever it is necessary to display a date or time in the TextBox.

There is some localization, but as all messages are hard coded in English, the control is really only useful in English speaking countries. The user can enter any valid date (valid according to the current local) into the TextBox, this will be parsed and redisplayed according to the formatting rules associated with the current selected FormatEx value.

A number of standard DateTimePicker properties have been overridden, these include ShowUpDown and ShowCheckBox. I wanted to ensure that these, along with the new property ShowButtons, which hides/unhide the buttons, were locked to false when the new property ReadOnly was true. ReadOnly sets/gets the TextBox ReadOnly property and acts to expose it in the property window, and makes that functionality available to the control.

I have added one other property LinkTo, which allows me to associate an instance of the control to one or more instances of the TAS.Widgets.DateTimePicker control. Using this, it is possible to synchronize the values of one or more controls with a master instance, so that I can display, for example, a date in one and the day of the week in another.

To Link other instances of the TAS.Widgets.DateTimePicker to a master instance add the name(s) of the linked controls to the LinkTo property of the master instance in the form of ChildControlName1,ChildControlName2,ChildControlName3 etc.

Using the code

To run the demo application, download DTP_Example.zip, and extract the files into a directory. The demo application WindowsApplication2.exe requires the file DateTimePicker.dll. If these two files are not extracted, the runtime error System.IO.FileNotFoundException has occurred in WindowsApplication2.exe will appear.

If you find this control useful, create a directory called TracyAnneSofware (or any name you like) and move it into that directory, then, if you use the Visual Studio IDE, add it to the tool box.

The code

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

namespace TAS.Widgets
{
    public class DateTimePicker : System.Windows.Forms.DateTimePicker
    {
        private System.Windows.Forms.TextBox txtDateTime;
        private System.ComponentModel.IContainer components;

        private bool SetDate;
        private System.Windows.Forms.ErrorProvider ErrorMessage;
        private System.Windows.Forms.ToolTip Tooltip;

        private const int BTNWIDTH = 16;

        public enum dtpCustomExtensions
        {
            dtpLong = 0,
            dtpShort = 1,
            dtpTime = 2,
            dtpShortDateShortTimeAMPM = 3,
            dtpShortDateLongTimeAMPM = 4,
            dtpShortDateShortTime24Hour = 5,
            dtpShortDateLongTime24Hour = 6,
            dtpLongDateShortTimeAMPM = 7,
            dtpLongDateLongTimeAMPM = 8,
            dtpLongDateShortTime24Hour = 9,
            dtpLongDateLongTime24Hour = 10,
            dtpSortableDateAndTimeLocalTime = 11,
            dtpUTFLocalDateAndShortTimeAMPM = 12,
            dtpUTFLocalDateAndLongTimeAMPM = 13,
            dtpUTFLocalDateAndShortTime24Hour = 14,
            dtpUTFLocalDateAndLongTime24Hour = 15,
            dtpShortTimeAMPM = 16,
            dtpShortTime24Hour = 17,
            dtpLongTime24Hour = 18,
            dtpYearAndMonthName = 19,
            dtpMonthNameAndDay = 20,
            dtpYear4Digit = 21,
            dtpMonthFullName = 22,
            dtpMonthShortName = 23,
            dtpDayFullName = 24,
            dtpDayShortName = 25,
            dtpShortDateAMPM = 26,
            dtpShortDateMorningAfternoon = 27,
            dtpCustom = 28
    }

        private string mvarLinkedTo;
        private bool bDroppedDown;
        private int ButtonWidth = BTNWIDTH;
        private bool mvarShowButtons = true;
        private dtpCustomExtensions mvarFormatEx;
        private string mvarCustomFormatMessage;
        private int CheckWidth = 0;

        private TAS.Widgets.DateTimePicker LinkTo;
        private System.Collections.ArrayList 
          LinkToArray = new System.Collections.ArrayList();
        private System.Collections.ArrayList 
          LinkedArray = new System.Collections.ArrayList();

        #region Constructor and destructor

        public DateTimePicker()
        {
            // This call is required by the Windows.Forms Form Designer.

            InitializeComponent();

            // TODO: Add any initialization after the InitForm call

            //Initialise bas.Format to Custom, 

            //we only need Custom Format

            base.Format = 
               System.Windows.Forms.DateTimePickerFormat.Custom;
            DateTimePicker_Resize(this, null);

        }

        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if( components != null )
                    components.Dispose();
            }
            base.Dispose( disposing );
        }

        #endregion Constructor and destructor

        #region Component Designer generated code
        /// <summary>

        /// Required method for Designer support - do not modify 

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.txtDateTime = new System.Windows.Forms.TextBox();
            this.ErrorMessage = new System.Windows.Forms.ErrorProvider();
            this.Tooltip = new 
               System.Windows.Forms.ToolTip(this.components);
            this.SuspendLayout();
            // 

            // txtDateTime

            // 

            this.txtDateTime.Location = new System.Drawing.Point(20, 49);
            this.txtDateTime.MaxLength = 50;
            this.txtDateTime.Name = "txtDateTime";
            this.txtDateTime.TabIndex = 0;
            this.txtDateTime.Text = "";
            this.txtDateTime.BackColorChanged += 
              new System.EventHandler(this.txtDateTime_BackColorChanged);
            this.txtDateTime.Leave += 
              new System.EventHandler(this.txtDateTime_Leave);
            this.txtDateTime.Enter += 
              new System.EventHandler(this.txtDateTime_Enter);
            // 

            // ErrorMessage

            // 

            this.ErrorMessage.DataMember = null;
            // 

            // DateTimePicker

            // 

            this.Controls.AddRange(new System.Windows.Forms.Control[] 
               {this.txtDateTime});
            this.Value = new System.DateTime(1753, 1, 1, 15, 8, 40, 119);
            this.DropDown += 
              new System.EventHandler(this.DateTimePicker_DropDown);
            this.FontChanged += 
              new System.EventHandler(this.DateTimePicker_FontChanged);
            this.Resize += 
              new System.EventHandler(this.DateTimePicker_Resize);
            this.Enter += 
              new System.EventHandler(this.DateTimePicker_Enter);
            this.CloseUp += 
              new System.EventHandler(this.DateTimePicker_CloseUp);
            this.ForeColorChanged += 
              new System.EventHandler
              (this.DateTimePicker_ForeColorChanged);
            this.BackColorChanged += 
              new System.EventHandler
              (this.DateTimePicker_BackColorChanged);
            this.ValueChanged += 
              new System.EventHandler(this.FormatOrValueChanged);
            this.FormatChanged += 
              new System.EventHandler(this.FormatOrValueChanged);
            this.ResumeLayout(false);

        }
        #endregion

        #region overriden and additional properties

        //OverRide Formst and hide it by setting 

        //Browsable false, make it read only

        //so it can't be written to, it will always be Custom anyway

        false)>
        public new System.Windows.Forms.DateTimePickerFormat Format
        {
            get
            {
                return base.Format;
            }
            //set

            //{

            //    base.Format = value;

            //}

        }

        //FormatEx, extends the formatting options 

        //by allowing additional selections

        //Replaces Format

        true), Category("Appearance"), 
          Description("Format Extensions replaces Format 
          gets sets display Formats")>
        public dtpCustomExtensions FormatEx
        {
            get
            {
                return mvarFormatEx;
            }
            set
            {
                mvarFormatEx = value;
                InitialiseCustomMessage();
            }
        }

        //New Property, allows hiding of DropDown 

        //Button and Updown Button

        true), Category("Appearance"), 
          Description("Hides DropDown and Spin Buttons, 
          Allows keyed entry only.")> 
        public bool ShowButtons
        {
            get
            {
                return mvarShowButtons;
            }
            set
            {
                //Do not allow Set Show Buttons when ReadOnly is true

                //all Buttons and Chexkbox are hidden 

                //when Control is Read Only

                if (!this.ReadOnly)
                {
                    mvarShowButtons = value;
                    if (mvarShowButtons)
                    {
                        ButtonWidth = BTNWIDTH;
                    }
                    else
                    {
                        ButtonWidth = 0;
                    }
                    DateTimePicker_Resize(this, null);
                }
            }
        }

        //Overrides base.ShowCheckBox

        true), Category("Appearance"), 
          Description("Hides DropDown and Spin Buttons, 
          Allows keyed entry only.")>
        public new bool ShowCheckBox
        {
            get
            {
                return base.ShowCheckBox;
            }
            set
            {
                //Do not allow set ShowCheckBox when ReadOnly is True

                //all Buttons and Chexkbox are hidden 

                //when Control is Read Only

                if (!this.ReadOnly)
                {
                    base.ShowCheckBox = value;
                    if (base.ShowCheckBox)
                    {
                        CheckWidth = BTNWIDTH;
                    }
                    else
                    {
                        CheckWidth = 0;
                    }
                    DateTimePicker_Resize(this,null);
                }
            }
        }
        
        //overrie Text, we want to set Get Textbox Text

        true), Category("Behavior"), 
          Description("Date and Time displayed")>
        public new string Text
        {
            get
            {
                return txtDateTime.Text;
            }
            set
            {
                txtDateTime.Text = value;
                //Don't bother Formatting the Textbox 

                //if it's value is NullString

                //It will cause problems if you do

                if (value != "")
                {
                    FormatTextBox();
                }
            }
        }

        //Override bas.ShowUpDown

        true), Category("Appearance"), 
          Description("Uses Updown control to select 
          dates instead of Dropdown control")>
        public new bool ShowUpDown
        {
            get
            {
                return base.ShowUpDown;
            }
            set
            {
                //Do not allow set ShowUpDown when ReadOnly is True

                //all Buttons and Checkbox are 

                //hidden when Control is Read Only

                if (!this.ReadOnly)
                {
                    base.ShowUpDown = value;
                    txtDateTime.Text = "";
                }
            }
        }

        //Override Textbox back Colour so we can 

        //add it to the Appearance List

        //and use it to set the BG colour

        true), Category("Appearance"), 
          Description("The Backround Colour user to display 
          Text and Graphics in this Control")>
        public new System.Drawing.Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
            }
        }

        //New Property Read Only makes it possible 

        //to set Textbox to read only

        true), Category("Behavior"), 
          Description("Used to set whether the 
                      control can be edited")>
        public bool ReadOnly
        {
            get
            {
                return txtDateTime.ReadOnly;
            }
            set
            {
                //If ReadOnly is true make sure 

                //ShowCheckBox, ShowUpDown and ShowButtons 

                //are false.

                //all Buttons and Checkbox are hidden 

                //when Control is Read Only

                //Be aware of the order these properties are set

                if (value)
                {
                    this.ShowCheckBox = false;
                    this.ShowUpDown = false;
                    this.ShowButtons = false;
                    txtDateTime.ReadOnly = value;
                }
                else
                {
                    txtDateTime.ReadOnly = value;
                    this.ShowButtons = true;
                }
            }
        }

        //New Property Makes it possible to link 

        //control to another Datetimepicker

        true), Category("Behavior"), 
          Description("Set Get another Date Picker Control 
          that this control receives data from.")>
        public string LinkedTo
        {
            get
            {
                return mvarLinkedTo;
            }
            set
            {
                mvarLinkedTo = value;
                LinkedArray.Clear();
                if (mvarLinkedTo != "" && mvarLinkedTo != null)
                {
                    string[] splitmvarLinkedTo = 
                       mvarLinkedTo.Split(",".ToCharArray());
                    for (int i = 0; i < splitmvarLinkedTo.Length; i++)
                    {    
                        LinkedArray.Add(splitmvarLinkedTo[i].Trim());
                    }
                }
            }
        }

        #endregion

        #region DateTimePicker events

        private void DateTimePicker_Resize(object sender, 
                                        System.EventArgs e)
        {
            this.txtDateTime.Location = new 
              System.Drawing.Point(-2 + CheckWidth, -2);
            this.txtDateTime.Size = new 
              System.Drawing.Size(this.Width - ButtonWidth - CheckWidth, 
              this.Height);
        }

        private void DateTimePicker_FontChanged(Object sender, 
                                            System.EventArgs e  ) 
        {
            //Make sure TextBox Font =  Dtp Font

            txtDateTime.Font = this.Font;
        }

        private void DateTimePicker_BackColorChanged(Object sender, 
                                                 System.EventArgs e)
        {
            //Make sure TextBox BackColour =  Dtp Back Colour

            txtDateTime.BackColor = this.BackColor;
        }

        private void txtDateTime_BackColorChanged(Object sender, 
                                             System.EventArgs e)
        {
            //Make sure DTP BackColour =  TextBox Back Colour

            if (txtDateTime.BackColor != this.BackColor)
            {
                this.BackColor = txtDateTime.BackColor;
            }
        }

        private void DateTimePicker_ForeColorChanged(Object sender, 
                                                System.EventArgs e)
        {
            //Make sure TextBox Fore Colour =  Dtp Fore Colour

            txtDateTime.ForeColor = this.BackColor;
        }

        private void FormatOrValueChanged(Object sender, 
                                       System.EventArgs e) 
        {
            ErrorMessage.SetError(this, "");

            //if dtp Value changed 

            //Attempt to Format the TextBox String 

            //if Text is not NullString

            if (this.Text != "" )
            {
                try
                {
                    FormatTextBox();
                }
                catch
                {
                    ErrorMessage.SetError(this, "Invalid Date - " 
                       + txtDateTime.Text + ", valid format is " 
                       + mvarCustomFormatMessage);
                }
            }
        }

        private void txtDateTime_Enter(Object sender, 
                                    System.EventArgs e  ) 
        {
            Tooltip.SetToolTip(txtDateTime, mvarCustomFormatMessage);

            if (txtDateTime.Text.Length > 0 )
            {
                txtDateTime.SelectionStart = 0;
                txtDateTime.SelectionLength = 
                         txtDateTime.Text.Length;
            }

            SetDate = true;
            this.Value = DateTime.Now;
            SetDate = false;
        }

        private void txtDateTime_Leave(Object sender, 
                                     System.EventArgs e ) 
        {
            if (! SetDate )
            {
                SetDate = true;

                ErrorMessage.SetError(this, "");

                //Attempt to Format the TextBox String 

                //if Text is not NullString

                if (this.Text != "" )
                {
                    try
                    {
                        FormatTextBox();
                        //if Link To is Not nullString

                        //Attempt to Link to the Specified LinkTo Controls

                        LinkToArray.Clear();
                        if (mvarLinkedTo != "" && mvarLinkedTo != null)
                        {
                          for (int j = 0; j < LinkedArray.Count; j++)
                          {
                            for (int i = 0; 
                               i < this.Parent.Controls.Count; i++)
                            {
                              if (this.Parent.Controls[i].Name == 
                                     LinkedArray[j].ToString() && 
                                     this.Parent.Controls[i] is 
                                     TAS.Widgets.DateTimePicker)
                              {
                                LinkTo = (TAS.Widgets.DateTimePicker)
                                               this.Parent.Controls[i];
                                LinkToArray.Add(LinkTo);
                                break;
                              }
                            }
                          }
                        }
                    }
                    catch 
                    {
                        ErrorMessage.SetError(this, "Invalid Date - " + 
                           txtDateTime.Text + ", valid format is " + 
                           mvarCustomFormatMessage);
                    }
                }

                //IF the LinkTo Object has been instantiated it's 

                //ok to attempt to set it's Text Value

                for (int i = 0; i < LinkToArray.Count; i++)
                {
                    if (this.LinkToArray[i] != null)
                    {
                        LinkTo = (TAS.Widgets.DateTimePicker)
                                                 LinkToArray[i];
                        LinkTo.Text = this.Text;
                    }
                }

                SetDate = false;
            }
        }

        private void DateTimePicker_Enter(Object sender, 
                                       System.EventArgs e)
        {
            txtDateTime.Focus();
        }

        private void DateTimePicker_DropDown(Object sender, 
                                         System.EventArgs e) 
        {
            bDroppedDown = true;
        }

        private void DateTimePicker_CloseUp(object sender, 
                                         System.EventArgs e)
        {
            if (bDroppedDown || this.ShowUpDown )
            {
                if (! SetDate )
                {
                    txtDateTime.Text = this.Value.ToString();
                    FormatTextBox();
                    bDroppedDown = false;
                    txtDateTime.Focus();
                }
            }
        }
    
        protected override void 
               OnValueChanged(System.EventArgs eventargs)
        {
            
            
            if (bDroppedDown || this.ShowUpDown )
            {
                if (! SetDate )
                {
                    txtDateTime.Text = this.Value.ToString();
                    FormatTextBox();
                }
            }
        }
        
        //Set up the message that will diplay in the Tooltip

        //when the mouse is hovered over the control

        private void InitialiseCustomMessage()
        {
            switch (mvarFormatEx)
            {
                case dtpCustomExtensions.dtpCustom:
                    mvarCustomFormatMessage = this.CustomFormat;
                    break;
                case dtpCustomExtensions.dtpLong:
                    mvarCustomFormatMessage = "Long Date (" + 
                         DateTime.Now.ToLongDateString() + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShort:
                    mvarCustomFormatMessage = "Short Date (" + 
                        DateTime.Now.ToShortDateString() + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpTime:
                    mvarCustomFormatMessage = "Long Time AM/PM (" + 
                        DateTime.Now.ToLongTimeString() + ")";
                    this.CustomFormat = "HH:mm:ss yyyy-MM-dd ";
                    break;
                case dtpCustomExtensions.dtpDayFullName:
                    mvarCustomFormatMessage = 
                        "Day of the Week Full Name (" + 
                        DateTime.Now.ToString("dddd", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "dd-MM-yyyy HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpDayShortName:
                    mvarCustomFormatMessage = 
                       "Day of the Week Short Name (" 
                       + DateTime.Now.ToString("ddd", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "dd-MM-yyyy HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpLongDateLongTime24Hour:
                    mvarCustomFormatMessage = 
                       "Long Date Long Time 24 Hour (" + 
                       DateTime.Now.ToString("D", 
                       Application.CurrentCulture) + " " + 
                       DateTime.Now.ToString("HH:mm:ss", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpLongDateLongTimeAMPM:
                    mvarCustomFormatMessage = 
                       "Long Date Long Time AM/PM (" + 
                       DateTime.Now.ToString("D", 
                       Application.CurrentCulture) + " " + 
                       DateTime.Now.ToString("hh:mm:ss tt", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpLongDateShortTime24Hour:
                    mvarCustomFormatMessage = 
                       "Long Date Short Time 24 Hour (" + 
                       DateTime.Now.ToString("D", 
                       Application.CurrentCulture) + " " + 
                       DateTime.Now.ToString("HH:mm", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpLongDateShortTimeAMPM:
                    mvarCustomFormatMessage = 
                       "Long Date Short Time AM/PM (" + 
                       DateTime.Now.ToString("D", 
                       Application.CurrentCulture) + " " + 
                       DateTime.Now.ToString("hh:mm tt", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpLongTime24Hour:
                    mvarCustomFormatMessage = 
                       "Long Time 24 Hour (" + 
                       DateTime.Now.ToString("HH:mm:ss", 
                       Application.CurrentCulture) + ")";
                    this.CustomFormat = "HH:mm:ss yyyy-MM-dd ";
                    break;
                case dtpCustomExtensions.dtpMonthFullName:
                    mvarCustomFormatMessage = 
                        "Month Full Name (" + 
                        DateTime.Now.ToString("MMMM", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "MM-dd-yyyy HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpMonthNameAndDay:
                    mvarCustomFormatMessage = 
                        "Month Name and Day (" + 
                        DateTime.Now.ToString("M", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "dd-MM-yyyy HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpMonthShortName:
                    mvarCustomFormatMessage = 
                        "Month Short Name (" + 
                        DateTime.Now.ToString("MMM", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "MM-dd-yyyy HH:mm:ss";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShortDateLongTime24Hour:
                    mvarCustomFormatMessage = 
                        "Short Date Long Time 24 Hour (" + 
                        DateTime.Now.ToString("d", 
                        Application.CurrentCulture) + " " + 
                        DateTime.Now.ToString("HH:mm:ss", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShortDateLongTimeAMPM:
                    mvarCustomFormatMessage = 
                        "Short Date Long Time AM/PM (" + 
                        DateTime.Now.ToString("G", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShortDateShortTime24Hour:
                    mvarCustomFormatMessage = 
                        " Short Date Short Time 24 Hour (" + 
                        DateTime.Now.ToString("d", 
                        Application.CurrentCulture) + " " + 
                        DateTime.Now.ToString("HH:mm", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShortDateShortTimeAMPM:
                    mvarCustomFormatMessage = 
                        " Short Date Short Time AM/PM (" + 
                        DateTime.Now.ToString("d", 
                        Application.CurrentCulture) + " " + 
                        DateTime.Now.ToString("hh:mmss tt", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpShortTime24Hour:
                    mvarCustomFormatMessage = 
                        "Short Time 24 Hour (" + 
                        DateTime.Now.ToString("HH:mm", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "HH:mm:ss yyyy-MM-dd ";
                    break;
                case dtpCustomExtensions.dtpShortTimeAMPM:
                    mvarCustomFormatMessage = 
                        "Short Time AM/PM (" + 
                        DateTime.Now.ToString("hh:mm tt", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "HH:mm:ss yyyy-MM-dd ";
                    break;
                case dtpCustomExtensions.dtpSortableDateAndTimeLocalTime:
                    mvarCustomFormatMessage = 
                        "Sortable Date and Local Time (" + 
                        DateTime.Now.ToString("s", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case dtpCustomExtensions.dtpUTFLocalDateAndLongTime24Hour:
                    mvarCustomFormatMessage = 
                        "UTF Local Date and Long Time 24 Hour (" + 
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpUTFLocalDateAndLongTimeAMPM:
                    mvarCustomFormatMessage = 
                        "UTF Local Date and Long Time AM/PM (" + 
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpUTFLocalDateAndShortTime24Hour:
                    mvarCustomFormatMessage = 
                        "UTF Local Date and Short Time 24 Hour (" + 
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpUTFLocalDateAndShortTimeAMPM:
                    mvarCustomFormatMessage = 
                        "UTF Local Date and Short Time AM/PM (" + 
                        DateTime.Now.ToString("yyyy-MM-dd HH:mm tt", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpYear4Digit:
                    mvarCustomFormatMessage = "4 Digit Year (" + 
                        DateTime.Now.ToString("yyyy", 
                        Application.CurrentCulture);
                    this.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpYearAndMonthName:
                    mvarCustomFormatMessage = 
                        "Year and Month Name (" + 
                        DateTime.Now.ToString("Y", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "MM-dd-yyyy HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpShortDateAMPM:
                    mvarCustomFormatMessage = "Short Date AM/PM (" + 
                        DateTime.Now.ToString("d", 
                        Application.CurrentCulture) + " " + 
                        DateTime.Now.ToString("tt", 
                        Application.CurrentCulture) + ")";
                    this.CustomFormat = "MM-dd-yyyy HH:mm:ss";
                    break;
                case  dtpCustomExtensions.dtpShortDateMorningAfternoon:
                    string AMPM = "AM";
                    if (DateTime.Now.Hour >= 12)
                    {
                        AMPM = "Afternoon";
                    }
                    mvarCustomFormatMessage = 
                        "Short Date Morning/Afternoon (" + 
                        DateTime.Now.ToString("d", 
                        Application.CurrentCulture) + " " + 
                        AMPM + ")";
                    this.CustomFormat = "MM-dd-yyyy HH:mm:ss";
                    break;
            }
            Tooltip.SetToolTip(txtDateTime, mvarCustomFormatMessage);
        }

        //Dispplay dates Times etc, based on Format selected

        private void FormatTextBox()
        {

            switch (mvarFormatEx)
            {
                case dtpCustomExtensions.dtpCustom:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = 
                           this.Value.ToString(this.CustomFormat, 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpDayFullName:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        int aDay;
                        DateTime aDate;
                        for (aDay = 1; aDay < 8; aDay++)
                        {
                            aDate = DateTime.Parse
                                    (DateTime.Now.Year.ToString() 
                                    + "-01-" + aDay.ToString());
                            if (aDate.DayOfWeek.ToString().ToLower() == 
                               txtDateTime.Text.ToLower() || 
                               aDate.DayOfWeek.ToString().
                               Substring(0, 3).ToLower() 
                               == txtDateTime.Text.ToLower())
                            {
                                this.Value = DateTime.Parse
                                  (DateTime.Now.Year.ToString() + 
                                  "-01-" + aDay.ToString());
                                break;
                            }
                        }
                    }
                    txtDateTime.Text = this.Value.ToString("dddd", 
                                       Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpDayShortName:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        int aDay;
                        DateTime aDate;
                        for (aDay = 1; aDay < 8; aDay++)
                        {
                            aDate = DateTime.Parse
                             (DateTime.Now.Year.ToString() + 
                             "-01-" + aDay.ToString());
                            if (aDate.DayOfWeek.ToString().ToLower() 
                              == txtDateTime.Text.ToLower() || 
                              aDate.DayOfWeek.ToString().Substring(0, 3).
                              ToLower() == txtDateTime.Text.ToLower())
                            {
                                this.Value = DateTime.Parse
                                  (DateTime.Now.Year.ToString() + 
                                  "-01-" + aDay.ToString());
                                break;
                            }
                        }
                    }
                    txtDateTime.Text = this.Value.ToString("ddd", 
                               Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpLongDateLongTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("D", 
                              Application.CurrentCulture) + " " + 
                              this.Value.ToString("HH:mm:ss", 
                              Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpLongDateLongTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("D", 
                              Application.CurrentCulture) + " " + 
                              this.Value.ToString("hh:mm:ss tt", 
                              Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpLongDateShortTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("D", 
                              Application.CurrentCulture) + " " + 
                              this.Value.ToString("HH:mm", 
                              Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpLongDateShortTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("D", 
                              Application.CurrentCulture) + " " + 
                              this.Value.ToString("hh:mm tt", 
                              Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpLongTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("HH:mm:ss", 
                              Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpMonthFullName:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        int aMonth;
                        DateTime aDate;
                        string[] sMonth = new string[]{"Jan","Feb",
                                "Mar","Apr","May","Jun","Jul","Aug",
                                "Sep","Oct","Nov","Dec"}; 
                        for (aMonth = 0; aMonth < 12; aMonth++)
                        {
                            aDate = DateTime.Parse
                                 (DateTime.Now.Year.ToString() + 
                                 "-" + (aMonth + 1) + "-" + "01");
                            if (sMonth[aMonth].ToLower() == 
                               txtDateTime.Text.ToLower() || 
                               sMonth[aMonth].ToLower() == 
                               txtDateTime.Text.Substring(0, 3).ToLower())
                            {
                                this.Value = DateTime.Parse
                                  (DateTime.Now.Year.ToString() 
                                  + "-"+ (aMonth + 1) + "-" + "01");
                                break;
                            }
                        }
                    }
                    txtDateTime.Text = this.Value.ToString("MMMM", 
                                        Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpMonthShortName:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        int aMonth;
                        DateTime aDate;
                        string[] sMonth = new string[]{"Jan",
                          "Feb","Mar","Apr","May","Jun","Jul",
                          "Aug","Sep","Oct","Nov","Dec"}; 
                        for (aMonth = 0; aMonth < 12; aMonth++)
                        {
                            aDate = DateTime.Parse
                               (DateTime.Now.Year.ToString() + 
                               "-" + (aMonth + 1) + "-" +  "01");
                            if (sMonth[aMonth].ToLower() == 
                               txtDateTime.Text.ToLower() || 
                               sMonth[aMonth].ToLower() == 
                               txtDateTime.Text.Substring(0, 3).ToLower())
                            {
                                this.Value = DateTime.Parse
                                   (DateTime.Now.Year.ToString() + 
                                   "-"+ (aMonth + 1) + "-" + "01");
                                break;
                            }
                        }
                    }
                    txtDateTime.Text = this.Value.ToString("MMM", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpMonthNameAndDay:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("M", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortDateLongTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("d", 
                           Application.CurrentCulture) + " " + 
                           this.Value.ToString("HH:mms:ss", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortDateLongTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("d", 
                           Application.CurrentCulture) + " " + 
                           this.Value.ToString("hh:mms:ss tt", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortDateShortTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("d", 
                           Application.CurrentCulture) + " " + 
                           this.Value.ToString("HH:mm", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortDateShortTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("d", 
                           Application.CurrentCulture) + " " + 
                           this.Value.ToString("hh:mms tt", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("HH:mm", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpShortTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("hh:mm tt", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpSortableDateAndTimeLocalTime:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("s", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpUTFLocalDateAndLongTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("yyyy-MM-dd", 
                           Application.CurrentCulture) + " " + 
                           this.Value.ToString("HH:mm:ss", 
                           Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpUTFLocalDateAndLongTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("yyyy-MM-dd", 
                            Application.CurrentCulture) + " " + 
                            this.Value.ToString("hh:mm:ss tt", 
                            Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpUTFLocalDateAndShortTime24Hour:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("yyyy-MM-dd", 
                            Application.CurrentCulture) + " " + 
                            this.Value.ToString("HH:mm", 
                            Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpUTFLocalDateAndShortTimeAMPM:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("yyyy-MM-dd", 
                            Application.CurrentCulture) + " " + 
                            this.Value.ToString("hh:mm tt", 
                            Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpYear4Digit:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        this.Value = DateTime.Parse("01 01 " + 
                                               txtDateTime.Text);
                    } 
                    txtDateTime.Text = this.Value.ToString("yyyy", 
                                      Application.CurrentCulture);
                    break;
                case dtpCustomExtensions.dtpYearAndMonthName:
                    try
                    {
                        this.Value = DateTime.Parse(txtDateTime.Text);
                    }
                    catch
                    {
                        try
                        {
                            txtDateTime.Text = 
                              DateTime.Now.Year.ToString() + " " + 
                              int.Parse(txtDateTime.Text, 
                              Application.CurrentCulture).ToString();
                        }
                        catch
                        {
                            this.Value = 
                                DateTime.Parse(txtDateTime.Text + 
                                " 01" );
                        }
                    }
                    txtDateTime.Text = this.Value.ToString("Y", 
                                    Application.CurrentCulture);
                    break;
                case  dtpCustomExtensions.dtpShortDateAMPM:
                    if (txtDateTime.Text.Substring
                        (txtDateTime.Text.Length - 2, 2).ToLower() 
                        == "pm")
                    {
                        txtDateTime.Text = 
                          txtDateTime.Text.Substring(0, 
                          txtDateTime.Text.Length - 2);
                        txtDateTime.Text = txtDateTime.Text + 
                          " 13:00";
                    }
                    else
                    {
                        if (txtDateTime.Text.Substring
                         (txtDateTime.Text.Length - 2, 2).
                          ToLower() == "am")
                        {
                            txtDateTime.Text = 
                               txtDateTime.Text.Substring(0, 
                               txtDateTime.Text.Length - 2);
                        }
                        txtDateTime.Text = txtDateTime.Text + " 01:00";
                    }
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToString("d", 
                            Application.CurrentCulture) + " " + 
                            this.Value.ToString("tt", 
                            Application.CurrentCulture);
                    break;
                case  dtpCustomExtensions.dtpShortDateMorningAfternoon:
                    string AMPM = "Morning";
                    if (txtDateTime.Text.Substring
                         (txtDateTime.Text.Length - 2, 2).
                         ToLower() == "pm")
                    {
                        txtDateTime.Text = 
                             txtDateTime.Text.Substring(0, 
                             txtDateTime.Text.Length - 2);
                        txtDateTime.Text = txtDateTime.Text + " 13:00";
                    }
                    else
                    {
                        if (txtDateTime.Text.Substring
                             (txtDateTime.Text.Length - 2, 2).
                             ToLower() == "am")
                        {
                            txtDateTime.Text = 
                               txtDateTime.Text.Substring(0, 
                               txtDateTime.Text.Length - 2);
                        }
                        txtDateTime.Text = txtDateTime.Text + " 01:00";
                    }
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    if (this.Value.Hour >= 12)
                    {
                        AMPM = "Afternoon";
                    }
                    txtDateTime.Text = this.Value.ToString("d", 
                            Application.CurrentCulture) + " " + AMPM;
                    break;
                case dtpCustomExtensions.dtpLong:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToLongDateString();
                    break;
                case dtpCustomExtensions.dtpShort:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToShortDateString();
                    break;
                case dtpCustomExtensions.dtpTime:
                    this.Value = DateTime.Parse(txtDateTime.Text);
                    txtDateTime.Text = this.Value.ToLongTimeString();
                    break;
                default:
                    break;
            }
        }

        #endregion

    }
}

Points of interest

As the code stands, it is only really useful in English speaking locations. While the control will accept dates and or times in any format that is valid for the current location, and display those dates and time correctly, based on the Format selected in FormatEx, all of the messages are in English.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralChanged code to have null value string on initialization
damijanc
23:27 26 Nov '09  
In designer after new() there is a code that sets value to New Date(CType(0, Long)). I added this to value property of control, to have null value string when there is no data bound. I also added check for DateTime.MinValue to get null value string when using new Date() for value.

 <Bindable(True)> _
<Browsable(False)> _
Public Shadows Property Value() As [Object]
Get
If _isNull Then
Return Nothing
Else
Return DateTime.MinValue
End If
End Get
Set(ByVal value As [Object])
If value Is Nothing OrElse value Is DBNull.Value OrElse (value.GetType() Is GetType(DateTime) And CDate(value) = DateTime.MinValue) OrElse (CDate(value) = New Date(CType(0, Long))) Then
SetToNullValue()
Else
SetToDateTimeValue()
MyBase.Value = DirectCast(value, DateTime)
End If
End Set
End Property

GeneralHow to implement an dpi independent approach? [modified]
inno1
23:30 2 Aug '09  
Hi,

program works fine but when setting dpi from 96 dpi to 120 or 192 dpi the control looks wrong.

Since I didn't find a way to access the width of the DateTimePicker-Button I ask here if someone has got a solution.

All the best!

inno

modified on Monday, August 3, 2009 5:52 AM

GeneralThanks a lot
wangkaijie
17:44 16 Apr '09  
These code is very useful to me.
GeneralError : Failed to create component .....
langtudien
23:52 22 Feb '09  
I use VS2005 and got this error message when trying to drop and drag this control from ToolBox to a form.

"Failed to create component ....." And then no control added to the form

How can i solve it ? Please help me!Rose
GeneralRe: Error : Failed to create component .....
pggrzesiak
4:16 17 Apr '09  
I use vs 2008 ee and I've got the same error

I don't know to do???

Someone have any solution???
GeneralRe: Error : Failed to create component .....
Adnan malik
0:48 8 Aug '09  
in VS.2008 you open project, Add reference by choosing browse and point to file DateTimePicker.dll from original source folder TAS_DateTimePicker/bin/debug.
From the same folder in toolbox of VS.net2008 IDE by dragging , add the same file.
Then when you drag this component, it will add fine on the form.

well now, I'm having problem in running mode that, when I;m selecting date it is not appearing on the textbox. Exploring more it to get it work.
GeneralGood Work Fiwel
ncristin
3:05 25 Jun '07  
Thank you very much. You solved my problem.;)
GeneralHow is the data binding ?
Lai Song Tsair
21:21 10 Jan '06  
When i bind into the data, the value was change as from data, but it does not save into database if i made change the date value ?

GeneralThe variable 'dtpCustomExtensions' is either undeclared or was never assigned.
gorolicek
11:59 22 Mar '05  
I get this error when compile.
Control seems to work OK, but it resets to dtpLong.
GeneralDisplay dates and times as blank
Fiwel
6:03 9 Mar '05  
You can solve it this way:

private System.Windows.Forms.DateTimePicker dateTimePicker1;
...
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.CustomFormat = " "; - Will do the job.

When user enters the correct date, you get:
ValueChanged event.
Change your CustomFormat at this point:
private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
if ("Neen to change format")
{
dateTimePicker1.CustomFormat = "MM/dd/yyyy hh:mm:ss tt"; // Or what ever...
("Neen to change format") = false;
}
}
Generalread-only?
georg74
3:28 26 Oct '04  
Is there a way to set DTP read-only at run time?
(Like EM_READONLY with edit box)

If not (I'm afraid that's the case) - I think it
is a great shame for API designer team. Frown
Am I overlooking something?

georg

GeneralRe: read-only?
Claudio Grazioli
22:15 18 Apr '05  
No you can't. As you can't with ComboBoxes and many other controls.

In my blog I describe a ReadOnly ComboBox. If you download the code the this ComboBox in the project you'll also find several other controls, one is a DateTimePicker with ReadOnly support.

Readonly ComboBox, Readonly DateTimePicker, Readonly NumericUpDown[^]

Claudio
Claudio's Website Hommingberger Gepardenforelle
GeneralGreat Control
shortstuff
11:29 6 Aug '04  
Smile You did an excellent job on the control. I have spent the last three days scouring the net for such a control. Most of the ones I found did not help at all and in some cases I could not even check...
It works great and I for one appreciate it. Keep up the great work.
Bruce...
USAFSmile
GeneralYour WinApplication2 is empty!
VRspace4
8:00 23 Jan '04  
I don't know how to use the datepicker class if the form is empty.
GeneralHResult from TimePicker object
SviluppatoreC#
0:20 29 Sep '03  
Hi,
I have insert the reference at DateTimePicker.dll in my project .. but when I insert the object in my project form ... run a message box that says "Exception in HRESULT: 0x80131019"!!!
Why??

Thanks Cry

GeneralClear DateTimPicker with minimum effort? I finally got it!!!
Jan Pichler
7:01 12 Aug '03  
Cool It's as easy as it can be:

Simply set the Filter attribute to "Custom" and the CustomFilter attribute to "''" (= two single quotes). Now the DateTimePicker box is empty, you can restore the display at any time by setting the CustomFilter attribute, eg. "MM/dd/yy". With a little program logic and handling of some major events (enter, leave, valueChanged etc.) it works perfect! Maybe there's someone who wants to implment this functionality into a class and post it here?

See you!

-JAN

GeneralWhere is those attributes?
seenit
16:26 10 Oct '03  
Where is Filter and CustomFilter attribute?
I found CustomFormat attribute. But I can't find Filter and CustomFilter attributes at DateTimePicker control.
GeneralRe: Where is those attributes?
Anonymous
3:11 11 Oct '03  
of course you're right. i was talking about the FORMAT and customFORMAT property. while writing the last post, i had some problems with sql (that's why i wrote 'filter')... D'Oh! sorry!

GeneralValue Change in DateTimePicker
reji jacob
2:30 12 Aug '03  
Hai

Uising the DateTimePicker Control I want to validate the
DateTimePicker Control. The ValueChange event is not Firing
what could be the reason?

regards
reji
GeneralRe: Value Change in DateTimePicker
IWishIWereClever
6:20 24 Feb '04  
This is down to what would appear to be a minor oversight by the author. Easy enough to make, I'm sure we've all done it...

Simple fix:
In the source code find the method 'protected override void OnValueChanged(System.EventArgs eventargs )' and add the following line at the end of it.

base.OnValueChanged( eventargs );

recompile the dll and voila!

The reason being that if you override the OnValueChanged event you still have to call the base class' method in order to inform any delegates of the event.
GeneralCan you add feature for monthcalendar?
woranop@pg
1:21 20 Jun '03  
If I want to know how to change monthcalendar.
In your project, Datetimepicker will show monthcalendar's Format depend on Window Regional Setting.If I want to set it,
how to change it.
Because I want to my program still show same monthcalendar's Format in any Window Regional Setting.
thank you

ps. I set window to thai regions but i want it to show in
us Format.

woranop@pg
woranop@progresssoftware.co.th
Generalproblem in tab control
dejital
5:59 24 Mar '03  
Hi, I think this control is absolutely wonderful, I have been looking for something like this for weeks! My only problem is when I use more than one of these DTP on a a tab control (one on 2 different tabs) and then bind them to 2 different database records, as soon as I hit the forward button to go to the next record, it just starts to fly un-controlably through all the records. This only happens after the second DTP on the second tab is bound to a field in the dataset.

Has anyone experienced this too an is there a fix?Confused
GeneralRe: problem in tab control
Anonymous
6:12 11 May '04  
Have you code sample of your problem?

Thanks, greetings

GeneralNice Job
ravinggoat
9:22 19 Mar '03  
Interesting control. Good work Smile
Generalerror
zjwuweim
14:58 11 Feb '03  
cann''t runBlush


Last Updated 5 Feb 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010