title: TextChanged want it to validate after the user has entered a date but it validates as the user is entering the date
body: <p>Hi Guys this must be a simple logic for most programmers but i am not able to figure it out.</p>
  
  <p>I have 2 datetimepicker on my windows form 
  datetimepicker 1 = fromdate
  datetimepicker 2 = todate</p>
  
  <p>the from date and to date i get from the below sql</p>
  
  <pre><code>   SELECT MIN(TransDate) AS mindate, MAX(TransDate) AS maxdate 
  FROM dbo.EtimePunchDetail WHERE (EmpID = @empid)
  </code></pre>
  
  <p>fromdate = mindate and todate = maxdate</p>
  
  <p>fromdate.mindate = mindate 
   todate.maxdate = maxdate ("So the user is only working with the selected date range")</p>
  
  <p>i added two textboxes with search functionality that the user can enter the fromdate and todate into and it checks against the mindate and maxdate and if the user enters a date out of the range i set the message box to throw an error </p>
  
  <p>I have an textbox changed even that has the following query:</p>
  
  <pre><code>      private void Min_TextChanged(object sender, EventArgs e)
          {
  
                DateTime date = DateTime.Parse(Min.Text);
  
                if (date &lt; DateTime.Parse(AvailableMin.Text))
                 {
                     MessageBox.Show("The Date you entered is either out of range or an invalid format");
                  }
                else
                  {
                    FromDate.MinDate = date;
                    FromDate.Value = date;
                  }
          }
  private void Max_TextChanged(object sender, EventArgs e)
      {
           DateTime date = DateTime.Parse(Max.Text);
  
           if (date &gt; DateTime.Parse(AvailableMax.Text))
           {
              MessageBox.Show("The Date you entered is either out of range or an invalid format");
           }
           else
           {
              ToDate.MaxDate = date;
              ToDate.Value = date;
           }
           }
  </code></pre>
  
  <p>But as i change the text the textchanged event gets fired with the message and is not letting me change the date or it says it is an invalid date. i want to be able to enter a date and then the textchanged should check to see if the date entered is not inrange how can i do that??</p>
  
  <p>here is a visual representation for what i am asking for:</p>
  
  <p><img src="https://i.stack.imgur.com/eJqdz.png" alt="enter image description here"></p>
  
  <p><strong>More Code on how i am getting the min and max date and the other things i am doing with those values i should have included this in my question before i apologize i thing the datetimepicker validation is interfering with the textbox validation</strong></p>
  
  <p><strong>Min and Max Value</strong></p>
  
  <pre><code>private void mindateset() // fill the listbox of values of mindate and maxdate
  {
  if (Employee.SelectedValue != null)
    {
  if (Employee.SelectedValue.ToString().Trim().Length &gt; 0)
      {
  try
       {
    using (MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
         {
     timepunchnew = new EtimeHistoryDataSet();
      connection.Open();
      using (MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT MIN(TransDate) AS mindate, MAX(TransDate) AS maxdate FROM dbo.EtimePunchDetail WHERE (EmpID = @empid)", connection))
      {
     MSSQL.SqlParameter myminparam = new MSSQL.SqlParameter();
     myminparam.Direction = ParameterDirection.Input;
     myminparam.ParameterName = "@empid";
     myminparam.Value = Employee.SelectedValue;
     command.Parameters.Add(myminparam);
     MSSQL.SqlDataAdapter myadapter = new System.Data.SqlClient.SqlDataAdapter();
     myadapter.SelectCommand = command;
     myadapter.Fill(timepunchnew, "Mindate");
     AvailableMin.DataSource = timepunchnew.Mindate;
     AvailableMin.DisplayMember = "mindate";
     AvailableMax.DataSource = timepunchnew.Mindate;
     AvailableMax.DisplayMember = "maxdate";
     FromDate.MinDate = DateTime.Parse(AvailableMin.Text);
     FromDate.Value = FromDate.MinDate;
     ToDate.MaxDate = DateTime.Parse(AvailableMax.Text);
     ToDate.Value = ToDate.MaxDate;
     Min.Text = FromDate.MinDate.ToString("d");
     Max.Text = ToDate.MaxDate.ToString("d");
     }
  }
  }
  catch (Exception) { /*Handle error*/ }
  
  }
  }
  
   }
  </code></pre>
  
  <p><strong>Validation on the datetimepicker values</strong></p>
  
  <pre><code>private void FromDate_ValueChanged_1(object sender, EventArgs e)
            {
           if (empchanging == false)
           {
            if (FromDate.Value &gt; ToDate.Value)
             {
               // MessageBox.Show("From Date Cannot Be Greater Than To Date");
                   if (DialogResult.OK == MessageBox.Show("From Date Cannot Be Greater Than To Date"))
                   {
                    FromDate.MinDate = DateTime.Parse(AvailableMin.Text);
                    FromDate.Value = FromDate.MinDate;
  
                  }
                }
            }
           }
        private void ToDate_ValueChanged_1(object sender, EventArgs e)
         {
         if (empchanging == false)
         {
         if (ToDate.Value &lt; FromDate.Value)
         {
        //MessageBox.Show("To Date Cannot Be Less Than From Date");
          if (DialogResult.OK == MessageBox.Show("To Date Cannot Be Less Than From Date"))
           {
           ToDate.MaxDate = DateTime.Parse(AvailableMax.Text);
           ToDate.Value = ToDate.MaxDate;
          }
       }
      }
       }
  </code></pre>
  
  <p><strong>Validating Available date range for empty string</strong></p>
  
  <pre><code>private void AvailableMin_SelectedIndexChanged(object sender, EventArgs e)
  {
   if (AvailableMin.Text == string.Empty)
    {
     textBox2.Visible = true;
    textBox2.Text = "There is no From Date available for this particular user";
  
  }
  else
  {
   textBox2.Visible = false;
   }
      }
  
  private void AvailableMax_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (AvailableMax.Text == string.Empty)
      {
        textBox1.Visible = true;
     textBox1.Text = "There is no To Date available for this particular user";
    }
    else
      {
     textBox1.Visible = false;
      }
      }
  </code></pre>
  
  <p><strong>I tried the below solution</strong></p>
  
  <pre><code> private void Min_TextChanged(object sender, EventArgs e)
   {
    DateTime date; 
  if (!DateTime.TryParse(Min.Text, out date))
         {
  formerrorprovider.SetError(this.Min,"The Date you entered is in invalid format");
    }
     else if (date &lt; DateTime.Parse(AvailableMin.Text))
   {
    formerrorprovider.SetError(this.Min, "The Date you entered is either out of range");
       }
      else 
     {
     formerrorprovider.SetError(this.Min, string.Empty);
      FromDate.MinDate = date;
      FromDate.Value = date;
       }
  </code></pre>
  
  <p><strong>it accepts the date i enter but is interfering with the datetimepicker validation.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/VkjvM.png" alt="enter image description here">
  <strong>PLZ HELP</strong></p>