Losing Focus without expanding DateTimePicker populates today's date as value

1 posts, 0 answers
  1. Priyam
    Priyam avatar
    6 posts
    Member since:
    Dec 2012

    Posted 21 Jan 2014 Link to this post

    When I tab through the controls in my form, and while tabbing through datetime picker Current Date is populated as value. I do not want to the control to enter any date without user selection. Also, I have a pair of datetime picker like start date and end date and each is of the control's Opened & Leave Events are utilized as below but without these also, the same issue occurs.
    private void dtProdStartDate_Leave(object sender, EventArgs e)
            {
                if (dtProdEndDate.Text == String.Empty && dtProdStartDate.Value != DateTime.Parse("1/1/0001"))
                {
                    DateTime dtStart = dtProdStartDate.Value;
                    dtStart = dtStart.AddMonths(1);
                    DateTime dtEnd = dtStart.AddDays(-dtStart.Day);
                    dtProdEndDate.Value = dtEnd;
                }
                else
                {
                    if (DateTime.Compare(dtProdStartDate.Value, dtProdEndDate.Value) > 0)
                    {
                        DateTime dtStart = dtProdStartDate.Value;
                        dtStart = dtStart.AddMonths(1);
                        DateTime dtEnd = dtStart.AddDays(-dtStart.Day);
                        dtProdEndDate.Value = dtEnd;
                    }
                }
            }
     
     private void dtProdStartDate_Opened(object sender, EventArgs e)
            {
                if (this.dtProdStartDate.Value == DateTime.MinValue)
                {
                    ((RadDateTimePickerCalendar)this.dtProdStartDate.DateTimePickerElement.GetCurrentBehavior()).Calendar.FocusedDate = DateTime.Now;
                }
            }
Back to Top