This is a migrated thread and some comments may be shown as answers.

DateTimePicker Canceling the ValueChanging Event

5 Answers 691 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Lasse
Top achievements
Rank 1
Lasse asked on 10 Apr 2012, 12:40 PM
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

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Apr 2012, 04:00 PM
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 >>
0
Allen
Top achievements
Rank 1
answered on 03 Sep 2013, 03:56 AM
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?
0
Peter
Telerik team
answered on 03 Sep 2013, 01:21 PM
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 >>
0
Allen
Top achievements
Rank 1
answered on 04 Sep 2013, 06:07 AM
that worked.

but would be better if the valuechanging event can be cancelled instead of hooking to the textboxelement. :)
0
Peter
Telerik team
answered on 09 Sep 2013, 05:12 AM
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 >>
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Lasse
Top achievements
Rank 1
Answers by
Peter
Telerik team
Allen
Top achievements
Rank 1
Share this question
or