DateTimePicker - time validation

2 posts, 1 answers
  1. Jeremy
    Jeremy avatar
    9 posts
    Member since:
    May 2009

    Posted 11 May 2011 Link to this post

    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
  2. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 17 May 2011 Link to this post

    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
  3. DevCraft banner
Back to Top