You must Sign In to post a response.
  • Category: .NET

    For Window Applications How to validate datetime picker "from date" to "To date "

    how to validate date time picker "from date" to "To date " and To date should not be greater than From date . me using date time picker its a custom control developed by someone it not contain "valuechanged event" and close up event". initially this date time picker(custom control) set as empty i have to select by mouse.
  • #691321
    Hello RajniKant,

    Try the below Code:

    private void dateTimePickerHolidayToDate_ValueChanged(object sender, EventArgs e)
    {
    DateTime fromdate = Convert.ToDateTime(dateTimePickerFromDate.Text);
    DateTime todate1 = Convert.ToDateTime(dateTimePickerToDate.Text);
    if (fromdate1 <= todate1)
    {
    TimeSpan daycount = todate1.Subtract(fromdate1);
    int dacount1 = Convert.ToInt32(daycount.Days) + 1;
    txtDay.Text = Convert.ToString(dacount1);
    }
    else
    {
    MessageBox.Show("From Date Must be Less Than To Date");
    }
    }

    Hope it helps you.

    Regards,
    Ankit Jain

  • #691326
    i used date time picker custom control initialy this picker value is"" and this cutom control dont have valuechanged event

  • #691327
    Hello Ankit

    i used date time picker custom control initialy this picker value is"" and this cutom control dont have valuechanged event

  • #691334
    Hi,

    If you don't have value changed event then do the validation on submit button click event. Since this is windows application it doesn't matter where you are doing the validation.


    Regards,
    Asheej T K

  • #691420
    Thank you Ankit Jain And Asheej T K
    i removed that date time picker custom control and used date time picker and text box. i put text box on date time picker and shown date time piker select option than i got this value changed event but it not works properly so i used close up event it works with Ankit logic


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.