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

DateTimePicker - time validation

1 Answer 79 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 11 May 2011, 07:04 PM

In the DataForm, when autogenerating fields for DateTime properties we're replacing the default control with the DateTimePicker.  Below is the code that replaces the textbox with the picker (e is an instance of DataFormAutoGeneratingFieldEventArgs):

var tabIndex = ((Control)e.Field.Content).TabIndex;
var picker = new Telerik.Windows.Controls.DateTimePicker { TabIndex = tabIndex };
  
var binding = e.Field.Content
    .GetBindingExpression(DatePicker.SelectedDateProperty)
    .ParentBinding.CreateCopy();
binding.Mode = BindingMode.TwoWay;
picker.SetBinding(DateTimePicker.SelectedDateTimeProperty, binding);
  
e.Field.Content = picker;

When a user enters garbage characters in the date portion of the picker ui, a tooltip appears with the word "Error" and the displayed date value is reverted to the property value.  The issue we're encountering is the the time entry portion of the picker ui does not behave the same way.  If you enter garbage characters in the time text box, the bad data entry just stays there, the binding doesn't get updated, nothing happens. 

How can I make the time field work like the date entry field?

Thanks,

jeremy

1 Answer, 1 is accepted

Sort by
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 17 May 2011, 10:21 AM
Hi Jeremy,

What I would suggest you is to handle the ParseDateTimeValue event of the RadDateTimePicker control - it allows to customize the behavior of the parser howerver you want to.

If you need further assistance don't hesitate to ask.

Regards,
Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
DateTimePicker
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Miroslav Nedyalkov
Telerik team
Share this question
or