locked
Visual Studio 2010 (VB) (Windows Forms) Datetimepicker validating event not firing....?? RRS feed

  • Question

  • Hi All. I am working in Visual Studio 2010, VB Windows forms.

    I have a datetime picker control on a form and I want to validate the Date selected/entered bu the user to be within a certain date range. (You can't use the value changed event because it starts an infinte loop when an invalid date is selected.

    I expected the validating event to handle this. Much to my chagrin, I discovered that the vaildating event does not fire, even though the causes validation property is set to true!

    Searching the forum, I noticed a post from 2005(!!??) that said basically "sure this does not work - but we'll fix it."

    I have been a microsoft user and supporter since 1979, but this is unconsionable.

    CLW


    With women, the TRUTH will not only NOT set you free, it will cause you a great deal of trouble.

    • Moved by Amanda Zhu Monday, October 7, 2013 5:52 AM
    Thursday, October 3, 2013 6:43 PM

Answers

  • This is not a forum for your question. You should probably submit a Bug Report.

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    • Proposed as answer by Frank L. Smith Monday, October 7, 2013 10:59 PM
    • Marked as answer by Carl Cai Monday, October 14, 2013 4:24 AM
    Monday, October 7, 2013 10:56 PM

All replies

  • Hello,

    I have moved this thread to Visual Basic forum for better response.

    Thanks,


    Amanda Zhu We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, October 7, 2013 5:52 AM
  • Why don't you set  Max and Min Date of Datetimepicker.

    With DtpPicker
                .MaxDate = "05/10/2013"
                .MinDate = "01/10/2013"
     End With


    Monday, October 7, 2013 7:23 AM
  • I used a combination of events in order to validate using the LostFocus event. I suppose it works but you need a control to pass focus to in other events. I used a TextBox.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub DateTimePicker1_Closeup(sender As Object, e As EventArgs) Handles DateTimePicker1.CloseUp ' Handles drop down list dismissed and disappearing
            TextBox1.Focus()
        End Sub
    
        Private Sub DateTimePicker1_Leave(sender As Object, e As EventArgs) Handles DateTimePicker1.Leave ' Handles input focus leaving the control
            TextBox1.Focus()
        End Sub
    
        Private Sub DateTimePicker1_LostFocus(sender As Object, e As EventArgs) Handles DateTimePicker1.LostFocus ' Handles DTP lost focus
            If DateTimePicker1.Value < Date.Today Then
                Me.Text = "Date cannot be before today."
            Else
                Me.Text = "No big deal"
            End If
        End Sub
    
        Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged ' Handles DTP value changed
            TextBox1.Focus()
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, October 7, 2013 7:38 AM
  • I eventually did this. However it was not the desired solution. I wanted to set the Min and Max date for the datetimepicker control based on the first date selected by the user.

    While this is a workaround, it still does not address the issue that it is something that has not been fixed in 8 years. Why allow the event if the control will never fire it?

    CLW

    PS thanks for the reply, it is sincerely appreciated.


    With women, the TRUTH will not only NOT set you free, it will cause you a great deal of trouble.

    Monday, October 7, 2013 5:11 PM
  • This is not a forum for your question. You should probably submit a Bug Report.

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    • Proposed as answer by Frank L. Smith Monday, October 7, 2013 10:59 PM
    • Marked as answer by Carl Cai Monday, October 14, 2013 4:24 AM
    Monday, October 7, 2013 10:56 PM