DateTimePicker Canceling the ValueChanging Event

6 posts, 0 answers
  1. Lasse
    Lasse avatar
    21 posts
    Member since:
    Jul 2011

    Posted 10 Apr 2012 Link to this post

    Hi,

    I have a form that allows the user to change from and to date.
    But if the user changes the "to date" to an illegal date (defined by the database) the user will get an message where he can override this error or not. If hi does not override it, i want the date to be reset (cancel the valuechanging) event. 
    But the value in the datetimepicker stays at the date selected by the user regardless of me doing cancel = true or not. 

    How can i achieve this functionality without triggering the change event once again?

    Regards
    Svein Thomas
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 12 Apr 2012 Link to this post

    Hello Svein,

    Thank you for contacting Telerik support.

    I was able to reproduce the described behavior.You can work around this by subscribing to the nested TextBoxElement ValueChangind event:
    private void Form1_Load(object sender, EventArgs e)
    {
    this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.ValueChanging += new CancelEventHandler(TextBoxElement_ValueChanging);
    }
     
    void TextBoxElement_ValueChanging(object sender, CancelEventArgs e)
    {
    Telerik.WinControls.UI.ValueChangingEventArgs args = e as Telerik.WinControls.UI.ValueChangingEventArgs;
    args.Cancel = true;
    }

    This is an issue of RadDateTimePicker and I have logged it to our Public Issue Tracker under ID 10696 . To vote for it and subscribe for its status updates, follow this link: http://www.telerik.com/support/pits.aspx#/public/winforms/10696.

    Please excuse us for the caused inconvenience.

    Your Telerik points have been updated.

    All the best,
    Peter
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Allen
    Allen avatar
    14 posts
    Member since:
    Aug 2012

    Posted 02 Sep 2013 Link to this post

    same problem here. i need to check the new value before i cancel the new value.

    by using this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.ValueChanging,  how can i check the new value entered?
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 03 Sep 2013 Link to this post

    Hello Allen,

    Thank you for contacting Telerik Support.

    You should cast the CancelEventArgs to ValueChangingEventArgs in order to get the new value from the ValueChangingEventArgs.NewValue property:
    private void Form1_Load(object sender, EventArgs e) 
    { 
    this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.ValueChanging += new CancelEventHandler(TextBoxElement_ValueChanging); 
    }   
     
    void TextBoxElement_ValueChanging(object sender, CancelEventArgs e) 
    { 
    Telerik.WinControls.UI.ValueChangingEventArgs args = e as Telerik.WinControls.UI.ValueChangingEventArgs;
    if( args.NewValue == null)
                  args.Cancel = true;
     
    }

    I hope this helps.

    Regards,
    Peter
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Allen
    Allen avatar
    14 posts
    Member since:
    Aug 2012

    Posted 04 Sep 2013 Link to this post

    that worked.

    but would be better if the valuechanging event can be cancelled instead of hooking to the textboxelement. :)
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 09 Sep 2013 Link to this post

    Hi Allen,

    This is an issue of RadDateTimePicker and this is logged in our Public Issue Tracker under ID 10696
    You can workaround this issue by handling the hosted MaskedText's ValueChanging event. This event requires casting from CancelEventArgs to ValueChangingEventArgs.

    Please, excuse us for the inconvenience. Do not hesitate to contact us if you have other questions.

    Regards,
    Peter
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready